C # ftp,getresponse (), Remote server return error _ Practical tips

Source: Internet
Author: User
Tags ftp client firewall
The general process of implementing FTP function in FtpWebRequest class
1, create a FtpWebRequest object, point to the FTP server URI
2, set the FTP implementation method (upload, download, etc.)
3. Set properties for FtpWebRequest objects (whether SSL is supported, binary transmissions are used, etc.)
4, Set login authentication (username, password)
5, the implementation of the request
6, receive the corresponding flow (if necessary)
7, if there is no open stream, then close the FTP request

Some of these important attributes are as follows:
· Credentials-Specifies the user name and password to log on to the FTP server.

· KeepAlive-Specifies whether the connection should be closed or closed after the request completes, and the default is True

· Usebinary-Specifies the type of file transfer. There are two types of file transfer modes, one is binary, and the other is ASCII. The 8th bit of the byte is different when the two methods are transferred. ASCII uses the 8th bit as error control, and the 8-bit binary is meaningful. So be careful when you use ASCII to transmit. Simply put, if you can read and write files in Notepad with ASCII transmission is safe, while others must use the binary mode. Of course, using binary mode to send ASCII files is also very good.

· Usepassive-Specifies whether active or passive mode is used. All previous clients used active mode and worked well, and now because of the presence of the client firewall, some ports will be closed so that the active mode will fail. In this case, passive mode is used, but some ports may also be blocked by the server's firewall. However, because the FTP server needs its FTP service to connect to a certain number of clients, they always support passive mode. This is why we use passive mode, in order to ensure that the data can be transmitted correctly, using passive mode is significantly better than active mode. (Translator Note: The active (port) mode establishes the data transmission channel is initiates by the server side, the server uses 20 ports to connect the client's one more than 1024 port; in the passive (PASV) mode, the data transmission channel is established by the FTP client, He uses a port greater than 1024 to connect to more than 1024 of the server's port.

· ContentLength-Setting this property is useful for the FTP server, but the client does not use it because FtpWebRequest ignores this property, so in this case the property is invalid. But if we set this property, the FTP server will anticipate the size of the file in advance (this happens when upload).

· Method-Specifies what command the current request is (upload,download,filelist, etc.). This value is defined in the webrequestmethods.ftp of the struct body.

When you encounter: "The remote server returned an error: (550) The file is not available (for example, files are not found, cannot access the file)", this may be the following reasons:
1.URL path is not correct to see if there are more spaces, or case problems
2. Whether the authority is sufficient
3. Need to repeatedly connect, such as getfilelist, need to get all the files recursively, KeepAlive set to False, a query after the request is closed.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.