This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes com.enterprisedt.net.ftp Ftp corrupts the tar.gz file while copying the file. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "com.enterprisedt.net.ftp Ftp corrupts the tar.gz file while copying the file." Watch "com.enterprisedt.net.ftp Ftp corrupts the tar.gz file while copying the file." New topic
Author

com.enterprisedt.net.ftp Ftp corrupts the tar.gz file while copying the file.

Andy Saxena
Greenhorn

Joined: Aug 09, 2012
Posts: 4
Guys,

I am in a situation where my ftp code copies the tar.gz file from the remote location. But that file is somehow corrupted. Mu unzip code in java fails, also, when I manually try to unzip the file in windows using WinRAR, it also says that the package is corrupted. Whereas the file in server is perfect.

I tried using Apache Commons Net FTP jar as well. But there also the same problem.

Below is my FTP code :

FileTransferClient ftp = null;
String fileName = "";
// create client
logger.info("\nCreating FTP client");
ftp = new FileTransferClient();
ftp.setRemoteHost(serverName);
ftp.setUserName(userName);
ftp.setPassword(password);
try {
ftp.connect();
} catch (Exception e) {
System.out.println("ERROR: ");
System.out.println("Please Check the Following :");
System.out.println("-> Server Name or IP Address");
System.out.println("-> User Name");
System.out.println("-> Password for <User Name> Account");
System.out.println("ERROR: Could not connect to server. DBX will now exit..");
System.exit(0);
}

logger.info("Connected and logged in to server " + serverName);
int index = remoteDir.lastIndexOf("/");
String parentRemoteDir = remoteDir.substring(0, index);
fileName = remoteDir.substring(index + 1);
ftp.changeDirectory(parentRemoteDir);

ftp.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.PASV);

ftp.setContentType(FTPTransferType.BINARY);
FTPFile[] files = ftp.directoryList(".");
if (loadMYSQLArchive) {

// get MYSQL Archives
boolean localDbxArchiveExists = (new File(localDir)).exists();
if (!localDbxArchiveExists) {
boolean createLocalDbxArchive = (new File(localDir)).mkdir();
if (createLocalDbxArchive) {
}
} else {
boolean createLocalDbxArchive = (new File(localDir)).mkdir();

if (createLocalDbxArchive) {
logger.info("Local directory created at \"" + localDir + "\"");
}
}
int dwnldedFiles = 0;
for (int i = 0; i < files.length; i++) {
if (!files[i].isDir() && files[i].getName().equalsIgnoreCase(fileName)) {
logger.info("Downloading file from \"" + files[i].getName() + " To location \"" + localDir + File.separator
+ files[i].getName() + "\"");
FileTransferInputStream downloadedStream = ftp.downloadStream(files[i].getName());
final FileOutputStream out = new FileOutputStream(localDir + File.separator + files[i].getName());
byte[] bytes = new byte[256];
int len;
while ((len = downloadedStream.read(bytes)) > 0) {
out.write(bytes, 0, len);
}
downloadedStream.close();
out.close();

// ftp.downloadFile(localDir + File.separator + files[i].getName(), files[i].getName());
dwnldedFiles++;
} else {
logger.info("Skipping directory " + files[i].getName());
}
}
if (dwnldedFiles == 0) {
throw new Exception("DB archive not found, please check the archive path.");
}

}
ftp.disconnect();

Please help me with this issue.

Thanks
~Andy
 
jQuery in Action, 2nd edition
 
subject: com.enterprisedt.net.ftp Ftp corrupts the tar.gz file while copying the file.
 
Similar Threads
send files over the socket
File sepearator for unix/windows problem
Reading log files from various unix servers through Java program on windows
problem retrieving a zip file from FTP server using org.apache.commons.net.ftp.
files are not delete