When using C# programs for FTP connections, various FTP-related settings may cause various types of problems, such as: connection failure, path not found, encoding errors, etc. However, FTP exceptions related to the capture system are sometimes not so detailed, and there may even be problems where the Log is not related to the actual problem. Therefore, I wrote this article to record possible problems and how to write programs to avoid problems and quickly test. .
Related settings
Active and passive modes : The first step in active and passive modes is to initiate a request from the client. The difference is that in active mode, after the client initiates the request, the server actively initiates a connection request to the client, while in passive mode, the client directly initiates a connection request. After the client is authenticated, it starts transmitting data. To use an analogy from my understanding, the active mode is more similar to Oauth's two-way authentication argentina whatsapp phone number mechanism, while the passive mode is where the client calls the API to request data from the server, so the connection is similar to the passive mode. Compared with the active mode, it is less likely to be blocked by the firewall, because the port and the connection must be open before the connection can be connected. The active mode requires one more step to initiate a request to the client. The external firewall on the server side and The client's firewall may affect the connection in this step.
FTP character encoding (codepage) : It is mainly related to the transmission of text files, such as txt, csv and other related files. Because different files have separation and newline symbols, and have different encoding methods for the same character, it will cause the transmission to pass. The text is garbled or incorrect. As for images or other files such as Excel and other binary files, this is theoretically not affected.
Supplement: Character encoding errors may cause the path to be incorrect or the path cannot be found when we connect to the FTP server. For example, if the folder contains Chinese characters and uses codepage 950 to connect, the folder name will be garbled, so it cannot be found. Relative path.
Transmission mode: divided into three types: FTPS, SFTP and FTP. In practice, FTP is not used because its data, account number and password are transmitted in plain text and are easily intercepted or attacked by a man-in-the-middle. SFTP and FTPS are both encrypted. The difference lies in the underlying method of implementing encryption. FTPS is based on the FTP transmission mode and uses SSL or TLS to encrypt the protocol. SFTP is based on SSH rather than a protocol running on FTP, but the data it transmits is also passed through Encrypted, in practice it is a choice based on the usage environment.