use of org.eclipse.ecf.filetransfer.SendFileTransferException in project ecf by eclipse.
the class ScpOutgoingFileTransfer method openStreams.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ecf.provider.filetransfer.outgoing.AbstractOutgoingFileTransfer
* #openStreams()
*/
protected void openStreams() throws SendFileTransferException {
try {
final File localFile = getFileTransferInfo().getFile();
// Set input stream from local file
setInputStream(new BufferedInputStream(new FileInputStream(localFile)));
final URL url = getRemoteFileURL();
this.username = url.getUserInfo();
scpUtil = new ScpUtil(this);
final Session s = scpUtil.getSession();
s.connect();
final String targetFileName = scpUtil.trimTargetFile(url.getPath());
final String command = SCP_COMMAND + targetFileName;
channel = (ChannelExec) s.openChannel(SCP_EXEC);
channel.setCommand(command);
final OutputStream outs = channel.getOutputStream();
responseStream = channel.getInputStream();
channel.connect();
scpUtil.checkAck(responseStream);
sendFileNameAndSize(localFile, targetFileName, outs, responseStream);
setOutputStream(outs);
} catch (final Exception e) {
throw new SendFileTransferException(NLS.bind(Messages.ScpOutgoingFileTransfer_EXCEPTION_CONNECTING, getRemoteFileURL().toString()), e);
}
}
use of org.eclipse.ecf.filetransfer.SendFileTransferException in project ecf by eclipse.
the class SendFileTransfer method openStreams.
/* (non-Javadoc)
* @see org.eclipse.ecf.provider.filetransfer.outgoing.AbstractOutgoingFileTransfer#openStreams()
*/
protected void openStreams() throws SendFileTransferException {
try {
// Get/open input file
setInputStream(new BufferedInputStream(new FileInputStream(getFileTransferInfo().getFile())));
// Open target
final IFileStore fileStore = EFS.getStore(new URI(getRemoteFileURL().getPath()));
setOutputStream(fileStore.openOutputStream(0, null));
} catch (final Exception e) {
throw new SendFileTransferException(e);
}
}
use of org.eclipse.ecf.filetransfer.SendFileTransferException in project ecf by eclipse.
the class MultiProtocolOutgoingAdapter method sendOutgoingRequest.
/* (non-Javadoc)
* @see org.eclipse.ecf.filetransfer.ISendFileTransferContainerAdapter#sendOutgoingRequest(org.eclipse.ecf.filetransfer.identity.IFileID, org.eclipse.ecf.filetransfer.IFileTransferInfo, org.eclipse.ecf.filetransfer.IFileTransferListener, java.util.Map)
*/
public void sendOutgoingRequest(IFileID targetID, IFileTransferInfo localFileToSend, IFileTransferListener transferListener, Map options) throws SendFileTransferException {
Assert.isNotNull(targetID);
Assert.isNotNull(localFileToSend);
Assert.isNotNull(transferListener);
String protocol = null;
try {
protocol = targetID.getURI().getScheme();
} catch (URISyntaxException e) {
try {
protocol = targetID.getURL().getProtocol();
} catch (final MalformedURLException e1) {
throw new SendFileTransferException(Messages.AbstractRetrieveFileTransfer_MalformedURLException);
}
}
ISendFileTransferContainerAdapter fileTransfer = Activator.getDefault().getSendFileTransfer(protocol);
// If no handler setup for this protocol then throw
if (fileTransfer == null) {
throw new SendFileTransferException(NLS.bind(Messages.MultiProtocolOutgoingAdapter_EXCEPTION_NO_PROTOCOL_HANDER, targetID));
}
fileTransfer.setConnectContextForAuthentication(connectContext);
fileTransfer.setProxy(proxy);
fileTransfer.sendOutgoingRequest(targetID, localFileToSend, transferListener, options);
}
use of org.eclipse.ecf.filetransfer.SendFileTransferException in project ecf by eclipse.
the class AbstractOutgoingFileTransfer method sendOutgoingRequest.
/* (non-Javadoc)
* @see org.eclipse.ecf.filetransfer.ISendFileTransferContainerAdapter#sendOutgoingRequest(org.eclipse.ecf.filetransfer.identity.IFileID, org.eclipse.ecf.filetransfer.IFileTransferInfo, org.eclipse.ecf.filetransfer.IFileTransferListener, java.util.Map)
*/
public void sendOutgoingRequest(IFileID targetReceiver, IFileTransferInfo localFileToSend, IFileTransferListener transferListener, Map ops) throws SendFileTransferException {
Assert.isNotNull(targetReceiver, Messages.AbstractOutgoingFileTransfer_RemoteFileID_Not_Null);
Assert.isNotNull(transferListener, Messages.AbstractOutgoingFileTransfer_TransferListener_Not_Null);
Assert.isNotNull(localFileToSend, Messages.AbstractOutgoingFileTransfer_EXCEPTION_FILE_TRANSFER_INFO_NOT_NULL);
this.done = false;
this.bytesSent = 0;
this.exception = null;
this.fileTransferInfo = localFileToSend;
this.remoteFileID = targetReceiver;
this.options = ops;
try {
this.remoteFileURL = targetReceiver.getURL();
} catch (final MalformedURLException e) {
throw new SendFileTransferException(NLS.bind(Messages.AbstractOutgoingFileTransfer_MalformedURLException, targetReceiver), e);
}
this.listener = transferListener;
setupProxies();
openStreams();
fireSendStartEvent();
setupAndScheduleJob();
}
use of org.eclipse.ecf.filetransfer.SendFileTransferException in project ecf by eclipse.
the class MultiProtocolOutgoingAdapter method sendOutgoingRequest.
public void sendOutgoingRequest(IFileID targetID, File outgoingFile, IFileTransferListener transferListener, Map options) throws SendFileTransferException {
Assert.isNotNull(targetID);
Assert.isNotNull(outgoingFile);
Assert.isNotNull(transferListener);
String protocol = null;
try {
protocol = targetID.getURI().getScheme();
} catch (URISyntaxException e) {
try {
protocol = targetID.getURL().getProtocol();
} catch (final MalformedURLException e1) {
throw new SendFileTransferException(Messages.AbstractRetrieveFileTransfer_MalformedURLException);
}
}
ISendFileTransferContainerAdapter fileTransfer = Activator.getDefault().getSendFileTransfer(protocol);
// If no handler setup for this protocol then throw
if (fileTransfer == null) {
if (protocol.equalsIgnoreCase("file")) {
// $NON-NLS-1$
fileTransfer = new LocalFileOutgoingFileTransfer();
}
}
if (fileTransfer == null) {
throw new SendFileTransferException(NLS.bind(Messages.MultiProtocolOutgoingAdapter_EXCEPTION_NO_PROTOCOL_HANDER, targetID));
}
fileTransfer.setConnectContextForAuthentication(connectContext);
fileTransfer.setProxy(proxy);
fileTransfer.sendOutgoingRequest(targetID, outgoingFile, transferListener, options);
}
Aggregations