次の方法を使用して、リモート サーバーからローカル マシンにファイルを FTP 転送しています。ログイン時のサーバーに入力パラメーターがない場合、これは正常に機能します。しかし、私はこのサーバーを持っているので、ログイン後に 1 を入力して、ホームページに移動する必要があります。したがって、サーバーでこのコードを実行すると、デフォルトでは、作業ディレクトリではなくホームページに移動します。どうすればこれを達成できますか? 私の方法;:
public void FtpFiles() {
try {
//new ftp client
FTPClient ftp = new FTPClient();
//try to connect
ftp.connect("FtpServerName");
//login to server
if (!ftp.login("serverusername", "serverpassword")) {
ftp.logout();
}
int reply = ftp.getReplyCode();
//FTPReply stores a set of constants for FTP reply codes.
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
}
//enter passive mode
ftp.enterLocalPassiveMode();
//get system name
System.out.println("Remote system is " + ftp.getSystemType());
//change current directory
ftp.changeWorkingDirectory("/ftadm/home/users/Statements/testStatements");
System.out.println("Current Statement directory is " + ftp.printWorkingDirectory());
//get list of filenames
FTPFile[] ftpFiles = ftp.listFiles();
if (ftpFiles != null && ftpFiles.length > 0) {
//loop thru files
for (FTPFile file : ftpFiles) {
if (!file.isFile()) {
continue;
}
System.out.println("Moving File File " + file.getName());
//get output stream
OutputStream output;
output = new FileOutputStream(pr.getHomeDirName() + file.getName());
//get the file from the remote system
ftp.retrieveFile(file.getName(), output);
//close output stream
output.close();
//delete the file
if (pr.deleteRemoteFiles() == true) {
ftp.deleteFile(file.getName());
}
}
}else{
System.out.println("Remote Directory is Empty");
}
ftp.logout();
ftp.disconnect();
} catch (Exception asd) {
System.out.println(asd.getMessage());
}
}
Apache FTP クライアント API を使用しています