Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DSDP - Target Management » How to programmatically upload a file to a remote server?
How to programmatically upload a file to a remote server? [message #583416] Mon, 21 June 2010 08:52
Vanessa Ramirez is currently offline Vanessa RamirezFriend
Messages: 4
Registered: June 2010
Junior Member
Hi everyone,

This is my first post and I am not sure if this is a proper question for this forum. However, I will give it a shot and hopefully someone can lead me to the right direction.

I am developing a plugin which uses RSE. One of the things I want to do is to upload a file to a remote system. What I was trying to do is to create a temporary file locally and upload it to the remote system. However I get an RSEF1002E error with no other information but this message:

Message reported from file system: Sftp: 4: Failure



I have tried to use copyWorkspaceResourcesToRemote from UniversalFileTransferUtility class, but since the file I create to copy is not in my workspace I can't make it work.

I would also want to refresh the folder tree view to reflect the new file but the registry.fireEvent method is not recognized as a method for the registry. I know that in the API it exists but I am not sure why is it that I can't use it.

Any help would be greatly appreciated.

The code I am using is the following:

private void uploadItfFile(String content, final IProgressMonitor monitor)
{
try
{

monitor.beginTask("Upload file", 25);
IHost theHost = getHost();
monitor.worked(1);

// get the IRemoteFileSubSystem
final ISystemRegistry registry = RSECorePlugin.getDefault().getSystemRegistry();
final IRemoteFileSubSystem fss = RemoteFileUtility.getFileSubSystem(theHost);

// make sure we are connected
if (!fss.isConnected()) {
monitor.subTask("Connecting");
connect(fss, new SubProgressMonitor(monitor, 5));
} else {
monitor.worked(5);
}

//TODO: Change this name of file
String itfdir = this.model.ItfDir+"/temp"+this.model.ItfFileName;

// Read IRemoteFile into cache while still in background job
// This is in order to speed up display of the remote folder dialog


// Select remote folder
final IRemoteFile targetFile = fss.getRemoteFileObject(itfdir);

if(!targetFile.exists())
fss.createFile(targetFile);

IRemoteFileSubSystem subsystem = targetFile.getParentRemoteFileSubSystem();
File itfFile = File.createTempFile("itftempfile",".java");

itfFile.deleteOnExit();

System.out.print("Temp file: "+itfFile.getAbsolutePath());

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(itfFile),"UTF8"));
out.write(content);
out.close();

//subsystem.upload(itfFile, targetFile, monitor);
subsystem.uploadUTF8(itfFile, targetFile, monitor);

//subsystem.uploadUTF8(itfFile.getAbsolutePath(), targetFile, monitor);

targetFile.getParentRemoteFile().markStale(true);


// fire a refresh event on the system registry
/*final IRemoteFile finFile = targetFile.getParentRemoteFile();
Display.getDefault().asyncExec(new Runnable() {
public void run() {
//registry.fireEvent(new SystemResourceChangeEvent(finFolder, ISystemResourceChangeEvents.EVENT_REFRESH, finFile));

}
});*/
Previous Topic:Enable compression
Next Topic:DSDP/TM 3.2 is released!
Goto Forum:
  


Current Time: Fri Apr 19 21:29:07 GMT 2024

Powered by FUDForum. Page generated in 0.02668 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top