Compare | upload | Download this is my first time to write Java program to achieve the company's requirements of the FTP data synchronization, all the original code as follows, for your reference and put forward valuable advice! In addition, I have two functions have not been achieved, please master Pointing twos: 1, how to delete the FTP server has been downloaded files? 2, how to upload the file name? Upload in front of the file name plus "Temp_", upload after the need to change the file name back. 3, how to use the Openpassivedataconnection () method to change the FTP connection to active connection, because the FTP server configured from the UNIX system to download files, you need to actively connect.
public void rename (String oldname,string newName) {
Aftp.renameto (Oldname,newname);
File old = new file (oldname); Oldname
File New = new file (newName); NewName
Aftp.renameto (NEW);
Boolean Old.renameto (File newName);
SYSTEM.OUT.PRINTLN (old);
System.out.println (NEW);
}
public static void Delefile (String rwfiledir) {
try {
Get TXT file in ReadFile directory
String Sdir = rwfiledir + "subunsubfromsp\\";
File Fdir = new file (sdir);
String FileName = "";
Int J = fdir.list (). length;
Number of files to delete in the System.out.println (sdir+ directory: +fdir.list (). length);
File file;
for (int i=0;i {
Delete txt file in Subunsubfromsp
FileName = Rwfiledir + "subunsubfromsp\\" + (Fdir.list ()) [0];
File = new file (FileName);
File.delete ();
System.out.println ("+filename+" file has been successfully deleted!) ");
}
//}
catch (IOException e) {
System.out.println ("Delete txt file error!");
E.printstacktrace ();
//}
}
public void Showfilecontents (String strdir)
{
StringBuffer buf = new StringBuffer ();
try {
AFTP.CD (Strdir);
Ins= aftp.list ();
while ((Ch=ins.read ()) >=0) {
Buf.append ((char) ch);
}
System.out.println (Buf.tostring ());
Ins.close ();
}
catch (IOException E)
{
}
}
Returns all files and folders in the current directory
Public ArrayList getfilelist () throws IOException {
BufferedReader dr = new BufferedReader (New InputStreamReader (Aftp.list ()));
ArrayList al = new ArrayList ();
String s = "";
while ((s = dr.readline ())!= null) {
Al.add (s);
}
Return al;
}
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.