大家好,任何java极客都可以帮助我吗?我需要将带有 subs 文件夹的文件夹上传到我的 ftp。我找到了一些示例代码,但仅适用于单个文件。而且我不知道如何更改它以上传文件夹。我使用谷歌但没有找到 anwser。
String server = "192.168.1.2";
String username = "test";
String password = "test";
String local = "mnt/sdcard/shopinglist/"; #This path i need to upload
FTPClient ftp = new FTPClient();
try
{
System.out.println( "Connecting" );
ftp.connect(server);
if(!ftp.login(username, password))
{
System.out.println( "Login failed" );
ftp.logout();
return;
}
int reply = ftp.getReplyCode();
System.out.println( "Connect returned: " + reply );
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
System.out.println( "Connection failed" );
return;
}
ftp.enterLocalPassiveMode();
FileInputStream in = new FileInputStream(local);
ftp.setFileType(ftp.BINARY_FILE_TYPE);
System.out.println( "Uploading File" );
boolean store = ftp.storeFile("mnt/sdcard/shopinglist/",in); # ??? Any help ???
in.close();
ftp.logout();
ftp.disconnect();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
谢谢大家。