Java
Chilkat2 Java
FTP Download File to a Stream
Demonstrates how to FTP download a file to a Chilkat stream.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Ftp2;
import com.chilkatsoft.chilkat2.Stream;
public class ChilkatExample {
public static void main(String[] args) {
// This example assumes the Chilkat FTP2 API to have been previously unlocked.
// See FTP2 Unlock Sample for sample code.
Ftp2 ftp = new Ftp2();
ftp.setHostname("my-ftp-server.com");
ftp.setPort(21);
ftp.setUsername("mFtpLogin");
ftp.setPassword("myFtpPassword");
ftp.setAuthTls(true);
ftp.setPassive(true);
// Connect and login to the FTP server using TLS.
try {
ftp.connect();
// Move to the sub-directory (from the FTP user's home directory) where the file is located.
ftp.changeRemoteDir("temp");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Stream to this local file:
Stream streamObj = new Stream();
streamObj.setSinkFile("c:/temp/qa_output/penguins2.jpg");
try {
ftp.getFileToStream("penguins2.jpg", streamObj);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
ftp.disconnect();
System.out.println("Success.");
}
}