FTP Transmission two ways

Source: Internet
Author: User
Tags ftp commands ftp protocol

Recently has been running no problem FTP download program has been a problem, the prompt can not be decompressed. After analysis, I use filezilla manual download after decompression is correct, and my program use Apache.common.FTP package download that there is a problem, cannot decompress. Comparing the two found that the latter file size is large. Find data as follows, the code will transfer mode to binary transmission download, problem solving.

for (Ftpfile ff:fsname) {

File LocalFile = new file (localpath+ "\" +ff.getname ());

is = new FileOutputStream (localfile);

Ftpclient.setcontrolencoding ("GBK");

Ftpclient.setfiletype (Ftp.binary_file_type);

Ftpclient.retrievefile (Ff.getname (), is);

Is.flush ();

Is.close ();

}
Analysis of the other company, is estimated to change the transmission mode, the FTP server to Linux after the use of binary upload, so the problem arises.

The FTP Protocol's task is to transfer files from one computer to another computer, regardless of where the two computers are located, how they are joined, or even whether they use the same operating system. If two computers are talking through the FTP protocol and have access to the Internet, you can use FTP commands to transfer files. There are some nuances in the use of each operating system, but the basic command structure for each protocol is the same.

There are two ways to transfer ftp: ASCII transfer mode and binary data transfer mode.

1. The ASCII transfer mode assumes that the file that the user is copying contains simple ASCII text, and if it is not UNIX running on the remote machine, FTP usually automatically adjusts the contents of the file when the file is transferred so that the file can be interpreted as another computer's format for storing text files.

However, it is often the case that the files that the user is transferring contain not text files, which may be programs, databases, word processing files, or compressed files (although the word processing file contains mostly text, which also contains nonprinting characters that indicate page size, font, etc.). Before copying any text file, use the binary command to tell the FTP verbatim copy, do not deal with these files, this is also the following to speak of the binary transmission.

2. Binary transmission mode in binary transmission, save the bit order of the file so that the original and the copy is one-bit corresponding. Even if the destination machine contains a bit sequence of files is meaningless. For example, the Macintosh delivers the executable to the IBM VM system in binary mode, and the file cannot be executed on the other side of the system. (However, it can be executed from a binary copy of the VM system to another Macintosh.)

If you transfer binary files in ASCII mode, they will still be translated even if they are not needed. This slows the transfer slightly, and it can damage the data, making the file unavailable. (on most computers, the ASCII method generally assumes that the first significant bit of each character is meaningless because the ASCII character combination does not use it.) If you transfer binary files, all bits are important. If you know that the two machines are the same, the binary is valid for both the text file and the data file.

So, this means that it's important to know what type of data you're transferring, and the table 6.1.1 gives hints of some common file types.

Table 6.1.1 Common file types

File

Way

Text file

Spreadsheet

Database file

Word Processor File

Program source Code

Electronic mail messages

UNIX "Shell Archive"

UNIX "Tar file"

Backup file

Compressed file

unencoded file

excutable file

Postscript file

Ascii

Mostly binary.

Mostly binary, or maybe ASCII.

Mostly binary, or maybe ASCII.

Ascii

Ascii

Ascii

Binary system

Binary system

Binary system

Ascii

Binary system

Binary system

Many database programs store data in binary format, even though the data is originally text-formatted. So, unless you know what your software is used for, we recommend that you try the database file in binary mode first. Then see if the file you're transferring is working correctly. If not, try another way. The executable file is typically a binary file.

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.