How to upload to FTP server in Java? -
i have following method upload_files ftp server, not receiving errors yet file not appearing on server after run. problem?
public static void upload_files(string un, string pw, string ip, string dir, string fn){ ftpclient client = new ftpclient(); fileinputstream fis = null; try { client.connect(ip); client.login(un, pw); string filename = dir+"/"+fn; fis = new fileinputstream(filename); client.storefile(filename, fis); client.logout(); } catch (ioexception e) { e.printstacktrace(); } { try { if (fis != null) { fis.close(); } client.disconnect(); system.out.println("uploaded"); } catch (ioexception e) { e.printstacktrace(); } } }
there number of possible issues. assumption using ftpclient 3.x apache commons-net. if using else, should indicate in question. ideas:
check reply status of connection make sure connecting expected. there's example on how in javadoc.
your
filename
variable path local file want send. same path want use storing file on server (relative ftp login root)? might be, isn't. if not, first parameter client.storefile(...) needs changed.most ftp servers provide ability log actions. able access yours? if so, makes clear going wrong.
Comments
Post a Comment