简体   繁体   English

文件上传到ftp和sftp

[英]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. 根据我的最新要求,我必须将文件上传到ftp或sftp服务器。 Problem is that I don't know that the server is ftp or sftp. 问题是我不知道服务器是ftp还是sftp。 On runtime client will provide the ip and other details of the server where I have to upload a file. 在运行时,客户端将提供我必须上传文件的服务器的IP和其他详细信息。 So, in runtime I have to understand that the server is ftp or sftp and then need to act accordingly. 因此,在运行时,我必须了解服务器是ftp还是sftp,然后需要采取相应的措施。 So, is there any way out on this? 那么,这有什么出路吗?

SFTP (SSH File Transfer Protocol) uses port 22 by default. 默认情况下,SFTP(SSH文件传输协议)使用端口22。

Some people use "SFTP" to denote the FTPS (FTP-over-TLS). 有些人使用“ SFTP”来表示FTPS(基于TLS的FTP)。 In this case you have two options: explicit TLS and implicit TLS. 在这种情况下,您有两个选择:显式TLS和隐式TLS。 Implicit TLS uses port 990 by default. 默认情况下,隐式TLS使用端口990。 In explicit mode the client connects to port 21 by default and then tells the server to start TLS handshake over existing connection. 在显式模式下,客户端默认情况下连接到端口21,然后告诉服务器通过现有连接启动TLS握手。

Plain FTP uses port 21. 普通FTP使用端口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). 在FTP / FTPS中,第一行应以220SP开头(SP代表空格,字符为0x20)。 Other response code can be given as well. 也可以给出其他响应代码。 In SSH/SFTP the line starts with "SSH-2.0-" . 在SSH / SFTP中,该行以“ SSH-2.0-”开头。

ftp and sftp will use different ports (21 and 22 respectively). ftp和sftp将使用不同的端口(分别为21和22)。 This should be part of the "ip and other details of the server". 这应该是“服务器的ip和其他详细信息”的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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