Any examples for connecting FTP over SSL (port 21)?

Advertisement

andegre
Joined:
Posts:
5

Any examples for connecting FTP over SSL (port 21)?

I only see examples on the website for SFTP. Is it as simple as replacing the SshHostKey property (leaving it blank) and setting the SslCertificate property (with the path to the file)?

FYI - Windows 7 64-bit
Latest version of WinSCP via .NET Assembly

Thanks

Reply with quote

Advertisement

andegre
Joined:
Posts:
5

Ok, finally was able to get a connection established, but the first time I tried to upload my test file it just hangs. I had to kill my program. Below is the SessionLogFile information....keep in mind that this information is repeated NUMEROUS times in the log file, there's some infinite loop going on.

Also, when I tried to run it a second time, it says that it cannot access my upload file because it's being used by another process....obviously WinSCP did not dipose of the resources.

Session log file:
< 2012-08-21 08:53:57.992 Script: Connecting to xxx.xxx.xxx.xxx ...
. 2012-08-21 08:53:57.993 Connecting to xxx.xxx.xxx.xxx ...
< 2012-08-21 08:53:57.993 Script: Connected with xxx.xxx.xxx.xxx, negotiating SSL connection...
. 2012-08-21 08:53:57.993 Connected with xxx.xxx.xxx.xxx, negotiating SSL connection...
< 2012-08-21 08:53:57.994 220 Microsoft FTP Service
> 2012-08-21 08:53:57.994 AUTH SSL
< 2012-08-21 08:53:57.994 234 AUTH command ok. Expecting TLS Negotiation.
< 2012-08-21 08:53:58.003 Script: SSL connection established. Waiting for welcome message...
. 2012-08-21 08:53:58.003 SSL connection established. Waiting for welcome message...
> 2012-08-21 08:53:58.003 USER ftpuser
< 2012-08-21 08:53:58.003 331 Password required for ftpuser.
> 2012-08-21 08:53:58.003 PASS ********
< 2012-08-21 08:53:58.004 230 User logged in.
> 2012-08-21 08:53:58.004 SYST
< 2012-08-21 08:53:58.005 215 Windows_NT
> 2012-08-21 08:53:58.005 FEAT
< 2012-08-21 08:53:58.005 211-Extended features supported:
< 2012-08-21 08:53:58.005 LANG EN*
< 2012-08-21 08:53:58.005 UTF8
< 2012-08-21 08:53:58.005 AUTH TLS;TLS-C;SSL;TLS-P;
< 2012-08-21 08:53:58.005 PBSZ
< 2012-08-21 08:53:58.005 PROT C;P;
< 2012-08-21 08:53:58.005 CCC
< 2012-08-21 08:53:58.005 HOST
< 2012-08-21 08:53:58.005 SIZE
< 2012-08-21 08:53:58.005 MDTM
< 2012-08-21 08:53:58.006 REST STREAM
< 2012-08-21 08:53:58.006 211 END
> 2012-08-21 08:53:58.006 OPTS UTF8 ON
< 2012-08-21 08:53:58.006 200 OPTS UTF8 command successful - UTF8 encoding now ON.
> 2012-08-21 08:53:58.006 PBSZ 0
< 2012-08-21 08:53:58.006 200 PBSZ command successful.
> 2012-08-21 08:53:58.006 PROT P
< 2012-08-21 08:53:58.007 200 PROT command successful.
< 2012-08-21 08:53:58.007 Script: Connected
. 2012-08-21 08:53:58.007 Connected
. 2012-08-21 08:53:58.007 Doing startup conversation with host.
< 2012-08-21 08:53:58.007 Script: Starting the session...
> 2012-08-21 08:53:58.007 PWD
< 2012-08-21 08:53:58.008 257 "/" is current directory.
< 2012-08-21 08:53:58.008 Script: Reading remote directory...
. 2012-08-21 08:53:58.008 Changing directory to "/".
> 2012-08-21 08:53:58.008 CWD /
< 2012-08-21 08:53:58.009 250 CWD command successful.
. 2012-08-21 08:53:58.009 Getting current directory name.
> 2012-08-21 08:53:58.009 PWD
< 2012-08-21 08:53:58.009 257 "/" is current directory.
. 2012-08-21 08:53:58.009 Startup conversation with host finished.
< 2012-08-21 08:53:58.009 Script: Session started.
. 2012-08-21 08:53:58.009 File: "C:\temp\install.log"
. 2012-08-21 08:53:58.010 Copying "C:\temp\install.log" to remote directory started.
. 2012-08-21 08:53:58.010 Binary transfer mode selected.
. 2012-08-21 08:53:58.010 Attempt to close connection due to fatal exception:
* 2012-08-21 08:53:58.010 Internal error fz#filetransfer (0010).
. 2012-08-21 08:53:58.010 Connection was lost, asking what to do.
. 2012-08-21 08:53:58.010 Asking user:
. 2012-08-21 08:53:58.010 Internal error fz#filetransfer (0010). ()
< 2012-08-21 08:54:03.011 Script: Disconnected from server
. 2012-08-21 08:54:03.011 Disconnected from server

Reply with quote

andegre
Joined:
Posts:
5

Ok, I figured out where the infinite loop is occurring (not why though).

When calling the Session.PutFiles() method, do NOT specify the remotePath parameter as "." (double-quote period doublequote)! I was under the impression that that meant the "local directory"...apparently not in this case.

So, I then changed that value to String.Empty, now I get this error (and it stops in a timely manner):

Session log file:
. 2012-08-21 09:27:28.119 --------------------------------------------------------------------------
. 2012-08-21 09:27:28.119 WinSCP Version 5.0.8 (Build 2438) (OS 6.1.7600)
. 2012-08-21 09:27:28.119 Configuration: nul
. 2012-08-21 09:27:28.120 Local account: IDOTCENTRAL\ganders
. 2012-08-21 09:27:28.120 Login time: Tuesday, August 21, 2012 9:27:28 AM
. 2012-08-21 09:27:28.120 --------------------------------------------------------------------------
. 2012-08-21 09:27:28.120 Session name: ftpuser@xxx.xxx.xxx.xxx (Ad-Hoc session)
. 2012-08-21 09:27:28.120 Host name: xxx.xxx.xxx.xxx (Port: 21)
. 2012-08-21 09:27:28.120 User name: ftpuser (Password: Yes, Key file: No)
. 2012-08-21 09:27:28.120 Tunnel: No
. 2012-08-21 09:27:28.120 Transfer Protocol: FTP
. 2012-08-21 09:27:28.120 Ping type: C, Ping interval: 30 sec; Timeout: 15 sec
. 2012-08-21 09:27:28.120 Proxy: none
. 2012-08-21 09:27:28.120 FTP: FTPS: Explicit SSL; Passive: Yes [Force IP: A]
. 2012-08-21 09:27:28.120 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2012-08-21 09:27:28.120 Cache directory changes: Yes, Permanent: Yes
. 2012-08-21 09:27:28.120 DST mode: 1
. 2012-08-21 09:27:28.120 --------------------------------------------------------------------------
. 2012-08-21 09:27:28.133 Connecting to xxx.xxx.xxx.xxx ...
. 2012-08-21 09:27:28.136 Connected with xxx.xxx.xxx.xxx, negotiating SSL connection...
< 2012-08-21 09:27:28.136 220 Microsoft FTP Service
> 2012-08-21 09:27:28.136 AUTH SSL
< 2012-08-21 09:27:28.136 234 AUTH command ok. Expecting TLS Negotiation.
. 2012-08-21 09:27:28.377 SSL connection established. Waiting for welcome message...
> 2012-08-21 09:27:28.377 USER ftpuser
< 2012-08-21 09:27:28.378 331 Password required for ftpuser.
> 2012-08-21 09:27:28.378 PASS ********
< 2012-08-21 09:27:28.379 230 User logged in.
> 2012-08-21 09:27:28.379 SYST
< 2012-08-21 09:27:28.379 215 Windows_NT
> 2012-08-21 09:27:28.380 FEAT
< 2012-08-21 09:27:28.380 211-Extended features supported:
< 2012-08-21 09:27:28.380 LANG EN*
< 2012-08-21 09:27:28.380 UTF8
< 2012-08-21 09:27:28.380 AUTH TLS;TLS-C;SSL;TLS-P;
< 2012-08-21 09:27:28.380 PBSZ
< 2012-08-21 09:27:28.380 PROT C;P;
< 2012-08-21 09:27:28.380 CCC
< 2012-08-21 09:27:28.380 HOST
< 2012-08-21 09:27:28.380 SIZE
< 2012-08-21 09:27:28.380 MDTM
< 2012-08-21 09:27:28.380 REST STREAM
< 2012-08-21 09:27:28.380 211 END
> 2012-08-21 09:27:28.380 OPTS UTF8 ON
< 2012-08-21 09:27:28.381 200 OPTS UTF8 command successful - UTF8 encoding now ON.
> 2012-08-21 09:27:28.381 PBSZ 0
< 2012-08-21 09:27:28.381 200 PBSZ command successful.
> 2012-08-21 09:27:28.381 PROT P
< 2012-08-21 09:27:28.382 200 PROT command successful.
. 2012-08-21 09:27:28.382 Connected
. 2012-08-21 09:27:28.382 --------------------------------------------------------------------------
. 2012-08-21 09:27:28.382 Using FTP protocol.
. 2012-08-21 09:27:28.382 Doing startup conversation with host.
> 2012-08-21 09:27:28.382 PWD
< 2012-08-21 09:27:28.383 257 "/" is current directory.
. 2012-08-21 09:27:28.383 Getting current directory name.
. 2012-08-21 09:27:28.383 Startup conversation with host finished.
< 2012-08-21 09:27:28.383 Script: Active session: [1] ftpuser@xxx.xxx.xxx.xxx
> 2012-08-21 09:27:28.664 Script: put -nopermissions -preservetime -transfer="binary" -- "C:\temp\install.log" ""
. 2012-08-21 09:27:28.665 Copying 1 files/directories to remote directory "/"
. 2012-08-21 09:27:28.665 PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask: "
. 2012-08-21 09:27:28.665 TM: B; ClAr: No; CPS: 0; InclM:
. 2012-08-21 09:27:28.665 AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2012-08-21 09:27:28.665 File: "C:\temp\install.log"
. 2012-08-21 09:27:28.666 Copying "C:\temp\install.log" to remote directory started.
. 2012-08-21 09:27:28.666 Binary transfer mode selected.
. 2012-08-21 09:27:28.667 Starting upload of C:\temp\install.log
> 2012-08-21 09:27:28.667 TYPE A
< 2012-08-21 09:27:28.667 200 Type set to A.
> 2012-08-21 09:27:28.667 PASV
< 2012-08-21 09:27:28.668 227 Entering Passive Mode (xxx.xxx.xxx.xxx,201,201).
> 2012-08-21 09:27:28.669 LIST
< 2012-08-21 09:27:28.671 150 Opening ASCII mode data connection.
. 2012-08-21 09:27:28.672 SSL connection established
< 2012-08-21 09:27:28.673 226 Transfer complete.
> 2012-08-21 09:27:28.674 TYPE I
< 2012-08-21 09:27:28.674 200 Type set to I.
> 2012-08-21 09:27:28.674 PASV
< 2012-08-21 09:27:28.675 227 Entering Passive Mode (xxx.xxx.xxx.xxx,201,202).
> 2012-08-21 09:27:28.676 STOR "
< 2012-08-21 09:27:28.677 550 The filename, directory name, or volume label syntax is incorrect.
. 2012-08-21 09:27:28.677 Copying files to remote side failed.
* 2012-08-21 09:27:28.678 (ExtException) Copying files to remote side failed.
* 2012-08-21 09:27:28.678 The filename, directory name, or volume label syntax is incorrect.
. 2012-08-21 09:27:28.678 Asking user:
. 2012-08-21 09:27:28.678 Error transferring file 'C:\temp\install.log'. ("Copying files to remote side failed.","The filename, directory name, or volume label syntax is incorrect. ")
* 2012-08-21 09:27:28.684 (EScpSkipFile) Error transferring file 'C:\temp\install.log'.
* 2012-08-21 09:27:28.684 Copying files to remote side failed.
* 2012-08-21 09:27:28.684 The filename, directory name, or volume label syntax is incorrect.
. 2012-08-21 09:27:28.684 Script: Failed
> 2012-08-21 09:27:29.166 Script: exit
. 2012-08-21 09:27:29.166 Script: Exit code: 1
. 2012-08-21 09:27:29.169 Disconnected from server

Reply with quote

andegre
Joined:
Posts:
5

Thanks to the thread entitle "Code to upload and download files via SFTP using WinSCP", I figured out what the issue is. For the remotePath property, if you don't want to change the remoteFolder to drop the file, enter "/" instead of anything else.

I will say the documentation is kind of lacking, and intellisese would be handy as well. Shouldn't be very hard to include in the next release.

Thanks andegre!

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Any examples for connecting FTP over SSL (port 21)?

The documentation by purpose does not suggest you anywhere to try to upload to "current directory" as there's no way to set one.
Though, if you insist on using the initial current directory (i.e. the home directory), use "./" (the docs says clearly that the path should be terminated with slash).
Definitely not the "/". That's root directory (what might be home directory on some server set ups).

Reply with quote

Advertisement

You can post new topics in this forum