简体   繁体   中英

File upload to ftp and sftp

I am stuck in a problem. According to my latest requirement, I have to upload a file to ftp or sftp server. Problem is that I don't know that the server is ftp or sftp. On runtime client will provide the ip and other details of the server where I have to upload a file. So, in runtime I have to understand that the server is ftp or sftp and then need to act accordingly. So, is there any way out on this?

SFTP (SSH File Transfer Protocol) uses port 22 by default.

Some people use "SFTP" to denote the FTPS (FTP-over-TLS). In this case you have two options: explicit TLS and implicit TLS. Implicit TLS uses port 990 by default. In explicit mode the client connects to port 21 by default and then tells the server to start TLS handshake over existing connection.

Plain FTP uses port 21.

Now, the user can be able to specify explicitly what protocol to use.

Finally you can try to connect, grab the first line of data from the socket and analyze it. In FTP/FTPS first line should start with 220SP (SP stands for space, character with the code of 0x20). Other response code can be given as well. In SSH/SFTP the line starts with "SSH-2.0-" .

ftp and sftp will use different ports (21 and 22 respectively). This should be part of the "ip and other details of the server".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM