Search in sources :

Example 1 with SendFileTransferException

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);
    }
}
Also used : SendFileTransferException(org.eclipse.ecf.filetransfer.SendFileTransferException) URL(java.net.URL) SendFileTransferException(org.eclipse.ecf.filetransfer.SendFileTransferException) Session(com.jcraft.jsch.Session)

Example 2 with SendFileTransferException

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);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) SendFileTransferException(org.eclipse.ecf.filetransfer.SendFileTransferException) URI(java.net.URI) FileInputStream(java.io.FileInputStream) SendFileTransferException(org.eclipse.ecf.filetransfer.SendFileTransferException)

Example 3 with SendFileTransferException

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);
}
Also used : ISendFileTransferContainerAdapter(org.eclipse.ecf.filetransfer.ISendFileTransferContainerAdapter) MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException) SendFileTransferException(org.eclipse.ecf.filetransfer.SendFileTransferException)

Example 4 with SendFileTransferException

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();
}
Also used : MalformedURLException(java.net.MalformedURLException) SendFileTransferException(org.eclipse.ecf.filetransfer.SendFileTransferException)

Example 5 with SendFileTransferException

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);
}
Also used : ISendFileTransferContainerAdapter(org.eclipse.ecf.filetransfer.ISendFileTransferContainerAdapter) MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException) SendFileTransferException(org.eclipse.ecf.filetransfer.SendFileTransferException)

Aggregations

SendFileTransferException (org.eclipse.ecf.filetransfer.SendFileTransferException)8 BufferedInputStream (java.io.BufferedInputStream)3 FileInputStream (java.io.FileInputStream)3 MalformedURLException (java.net.MalformedURLException)3 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 ISendFileTransferContainerAdapter (org.eclipse.ecf.filetransfer.ISendFileTransferContainerAdapter)2 Session (com.jcraft.jsch.Session)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ProtocolException (java.net.ProtocolException)1 URI (java.net.URI)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IFileTransferInfo (org.eclipse.ecf.filetransfer.IFileTransferInfo)1 XMPPFileID (org.eclipse.ecf.provider.xmpp.identity.XMPPFileID)1 XMPPException (org.jivesoftware.smack.XMPPException)1