mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-10 10:35:23 +02:00
Fixing 140408 - FTP Upload does not work.
This commit is contained in:
parent
a2c2b82335
commit
b761dbbd49
3 changed files with 62 additions and 54 deletions
|
@ -11,7 +11,7 @@
|
||||||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* {Name} (company) - description of contribution.
|
* Michael Berger (IBM) - Fixing 140408 - FTP upload does not work
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.services.files.ftp;
|
package org.eclipse.rse.services.files.ftp;
|
||||||
|
@ -30,8 +30,9 @@ public class FTPHostFile implements IHostFile
|
||||||
private boolean _isArchive = false;
|
private boolean _isArchive = false;
|
||||||
private long _lastModified = 0;
|
private long _lastModified = 0;
|
||||||
private long _size = 0;
|
private long _size = 0;
|
||||||
|
private boolean _exists = false;
|
||||||
|
|
||||||
public FTPHostFile(String parentPath, String name, boolean isDirectory, boolean isRoot, long lastModified, long size)
|
public FTPHostFile(String parentPath, String name, boolean isDirectory, boolean isRoot, long lastModified, long size, boolean exists)
|
||||||
{
|
{
|
||||||
_parentPath = parentPath;
|
_parentPath = parentPath;
|
||||||
_name = name;
|
_name = name;
|
||||||
|
@ -40,6 +41,7 @@ public class FTPHostFile implements IHostFile
|
||||||
_lastModified = lastModified;
|
_lastModified = lastModified;
|
||||||
_size = size;
|
_size = size;
|
||||||
_isArchive = internalIsArchive();
|
_isArchive = internalIsArchive();
|
||||||
|
_exists = exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName()
|
||||||
|
@ -76,7 +78,7 @@ public class FTPHostFile implements IHostFile
|
||||||
|
|
||||||
public boolean exists()
|
public boolean exists()
|
||||||
{
|
{
|
||||||
return true;
|
return _exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAbsolutePath()
|
public String getAbsolutePath()
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* {Name} (company) - description of contribution.
|
* Michael Berger (IBM) - Fixing 140408 - FTP upload does not work
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.services.files.ftp;
|
package org.eclipse.rse.services.files.ftp;
|
||||||
|
@ -74,7 +74,7 @@ public class FTPLinuxDirectoryListingParser implements IFTPDirectoryListingParse
|
||||||
}
|
}
|
||||||
catch (Exception e) {}
|
catch (Exception e) {}
|
||||||
}
|
}
|
||||||
return new FTPHostFile(parentPath, name, isDirectory, false, lastMod, length);
|
return new FTPHostFile(parentPath, name, isDirectory, false, lastMod, length, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -11,7 +11,7 @@
|
||||||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* {Name} (company) - description of contribution.
|
* Michael Berger (IBM) - Fixing 140408 - FTP upload does not work
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.services.files.ftp;
|
package org.eclipse.rse.services.files.ftp;
|
||||||
|
@ -20,10 +20,13 @@ import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -51,6 +54,7 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
|
||||||
private transient String _hostname;
|
private transient String _hostname;
|
||||||
private transient String _userId;
|
private transient String _userId;
|
||||||
private transient String _password;
|
private transient String _password;
|
||||||
|
private URLConnection _urlConnection;
|
||||||
|
|
||||||
public FTPService()
|
public FTPService()
|
||||||
{
|
{
|
||||||
|
@ -141,7 +145,10 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
|
||||||
{
|
{
|
||||||
return matches[0];
|
return matches[0];
|
||||||
}
|
}
|
||||||
return null;
|
else
|
||||||
|
{
|
||||||
|
return new FTPHostFile(remoteParent, fileName, false, false, 0, 0, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public boolean isConnected()
|
public boolean isConnected()
|
||||||
{
|
{
|
||||||
|
@ -208,55 +215,44 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
|
||||||
|
|
||||||
public boolean upload(IProgressMonitor monitor, File localFile, String remoteParent, String remoteFile, boolean isBinary, String srcEncoding, String hostEncoding)
|
public boolean upload(IProgressMonitor monitor, File localFile, String remoteParent, String remoteFile, boolean isBinary, String srcEncoding, String hostEncoding)
|
||||||
{
|
{
|
||||||
FtpClient ftp = getFTPClient();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ftp.cd(remoteParent);
|
FileInputStream fis = new FileInputStream(localFile);
|
||||||
if (isBinary)
|
return upload(monitor, fis, remoteParent, remoteFile, isBinary, hostEncoding);
|
||||||
ftp.binary();
|
|
||||||
else
|
|
||||||
ftp.ascii();
|
|
||||||
ftp.put(localFile.getAbsolutePath());
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private OutputStream getUploadStream(String remotePath, boolean isBinary) throws Exception
|
||||||
|
{
|
||||||
|
String typecode = isBinary ? "i" : "a";
|
||||||
|
remotePath = "%2F" + remotePath;
|
||||||
|
remotePath = remotePath.replaceAll(" ", "%20");
|
||||||
|
URL url = new URL("ftp://" + _userId + ":" + _password + "@" + _hostname + "/" + remotePath + ";type=" + typecode);
|
||||||
|
_urlConnection = url.openConnection();
|
||||||
|
return _urlConnection.getOutputStream();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean upload(IProgressMonitor monitor, InputStream stream, String remoteParent, String remoteFile, boolean isBinary, String hostEncoding)
|
public boolean upload(IProgressMonitor monitor, InputStream stream, String remoteParent, String remoteFile, boolean isBinary, String hostEncoding)
|
||||||
{
|
{
|
||||||
// hack for now
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BufferedInputStream bis = new BufferedInputStream(stream);
|
BufferedInputStream bis = new BufferedInputStream(stream);
|
||||||
File tempFile = File.createTempFile("ftp", "temp");
|
String remotePath = remoteParent + getSeparator() + remoteFile;
|
||||||
FileOutputStream os = new FileOutputStream(tempFile);
|
OutputStream os = getUploadStream(remotePath, isBinary);
|
||||||
BufferedOutputStream bos = new BufferedOutputStream(os);
|
byte[] buffer = new byte[1024];
|
||||||
|
int readCount;
|
||||||
byte[] buffer = new byte[1024];
|
while( (readCount = bis.read(buffer)) > 0)
|
||||||
int readCount;
|
|
||||||
while( (readCount = bis.read(buffer)) > 0)
|
|
||||||
{
|
|
||||||
bos.write(buffer, 0, readCount);
|
|
||||||
}
|
|
||||||
bos.close();
|
|
||||||
|
|
||||||
FtpClient ftp = getFTPClient();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ftp.cd(remoteParent);
|
|
||||||
if (isBinary)
|
|
||||||
ftp.binary();
|
|
||||||
else
|
|
||||||
ftp.ascii();
|
|
||||||
ftp.put(tempFile.getAbsolutePath());
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
os.write(buffer, 0, readCount);
|
||||||
}
|
}
|
||||||
|
os.close();
|
||||||
|
bis.close();
|
||||||
|
_urlConnection = null;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -323,7 +319,7 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
|
||||||
|
|
||||||
public IHostFile[] getRoots(IProgressMonitor monitor)
|
public IHostFile[] getRoots(IProgressMonitor monitor)
|
||||||
{
|
{
|
||||||
IHostFile root = new FTPHostFile("/", "/", true, true, 0, 0);
|
IHostFile root = new FTPHostFile("/", "/", true, true, 0, 0, true);
|
||||||
return new IHostFile[] { root };
|
return new IHostFile[] { root };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,33 +337,43 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IHostFile createFolder(IProgressMonitor monitor, String remoteParent, String folderName) {
|
public IHostFile createFolder(IProgressMonitor monitor, String remoteParent, String folderName)
|
||||||
// TODO Auto-generated method stub
|
{
|
||||||
return null;
|
try
|
||||||
|
{
|
||||||
|
FTPClientService ftp = getFTPClient();
|
||||||
|
ftp.cd(remoteParent);
|
||||||
|
ftp.sendCommand("MKD " + folderName);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return getFile(monitor, remoteParent, folderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean delete(IProgressMonitor monitor, String remoteParent, String fileName) {
|
public boolean delete(IProgressMonitor monitor, String remoteParent, String fileName)
|
||||||
// TODO Auto-generated method stub
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean rename(IProgressMonitor monitor, String remoteParent, String oldName, String newName) {
|
public boolean rename(IProgressMonitor monitor, String remoteParent, String oldName, String newName)
|
||||||
// TODO Auto-generated method stub
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean rename(IProgressMonitor monitor, String remoteParent, String oldName, String newName, IHostFile oldFile) {
|
public boolean rename(IProgressMonitor monitor, String remoteParent, String oldName, String newName, IHostFile oldFile)
|
||||||
// TODO Auto-generated method stub
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean move(IProgressMonitor monitor, String srcParent, String srcName, String tgtParent, String tgtName) {
|
public boolean move(IProgressMonitor monitor, String srcParent, String srcName, String tgtParent, String tgtName)
|
||||||
// TODO Auto-generated method stub
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean copy(IProgressMonitor monitor, String srcParent, String srcName, String tgtParent, String tgtName) {
|
public boolean copy(IProgressMonitor monitor, String srcParent, String srcName, String tgtParent, String tgtName)
|
||||||
// TODO Auto-generated method stub
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue