SFTP ; SSH_FX_FAILURE:

Hi.
I am trying to do a fsetstat on a file using sftp:
fileAttributes = sftpClient.fstat(fileHandle);
fileAttributes.permissions = new Integer(00777);
sftpClient.fsetstat(fileHandle, fileAttributes);
The files permission gets changed as requested on the server but an exception gets thrown, I can�t figure out why the exception is thrown :SSH_FX_FAILURE: An error occurred, but no specific error code exists to describe the failure.
I am able to do createFile which indicates that my connection and file handle is working...
Also the file gets created by the process and therefor I have all the neccesary permission to make changes to the file.
Thanks

This is not a permission problem but a problem between Contribute and the FTP server.  This is an issue that has been around for at least 5 years, best I can tell.  We are seeing the Contribute user log in just fine but when they want to edit a file Contribute immediately tries to read the .lck file which returns an "Access Denied" error. The .lck file does not exist at this point which is causing this whole problem. If I create a blank text file and name it "default.htm.lck" and then try to edit the default.htm things are just fine. The user clicks the edit button, Contribute makes a call to the file system to read the .lck file, finds it, it's blank and has no information to read so it goes ahead and lets the user edit the page. When the user finishes the edit and uploads the file Contribute deletes the .lck file and then back to the "Access Denied" error for the next time.
To test this I have two sFTP servers and one web server.  The two FTP server authenticate via Active Directory and connect to the webserver via UNC paths.  The two FTP servers are running different software for the FTP part, one works the other does not.
trying to get a nonexistent file from the working FTP server results in
Code:
psftp> get bla.htm
/bla.htm: open for read: no such file or directory
trying to get a nonexistent file from the other FTP server results in
Code:
psftp> get bla.htm
/bla.htm: open for read: failure
From what I can gather at http://www.justskins.com/forums/contribute-cannot-edit-files-over-sftp-4977.html the server is returning an error code 4, a general sftp error. what Contribute is expecting is a error code 2, file not found.  Why some FTP servers return the error code 4, I have no clue.  But who thought it would be a good idea to open a file that may or may not exist?  Wouldn't it have been easier to check for the lck file first?

Similar Messages

  • Using secure FTP (SFTP) with XI 3.0.

    Hi,
    I must bring a document with SFTP protocol.
    Is it possible use SFTP with XI 3.0. What must I do use SFTP with XI. Is it necessary to install some component to XI or it needs some 3hrd party components?
    Thanks

    Hi Cemil,
    Right now, XI does not have the feature of communicating with SFTP. You can extend the functionality of the File Adapter by writing some adapter modules to enable it to communicate with SFTP.
    Regards,
    Hari.

  • Java SFTP API/Sample application

    I'm looking for either sample java code of how to send files via sftp or a java api to do this. Jscape looks to be the standard for doing this although it costs quite a bit, wondering if there is free code out there?
    Thanks for any help in advance!!!

    Check out JCraft's Java Secure Channel (JSch) project -- it's an implementation of SSH (with scp, sftp, etc.) in Java -- with some examples that might get you started: http://www.jcraft.com/jsch/
    The code is distributed free under a BSD-style license which is described on the site.
    Greg

  • Cannot login via ssh/sftp from certain clients

    Hi Guys,
    Strange issue here. I have a machine running 10.7.4 that I want to be able to access via sftp/ssh.
    I can login into the machine in terminal using either ssh or sftp.
    I cannot however login to the machine from finder via sftp. I am just told the username/password is wrong.
    Equally I cannot login to the machine from certain clients on my android phone (the main reason I need sftp)
    I can however login from cyberduck on the other machines I have, and from some clients on my android phone.
    When a mac is denied access it gives authentication failed as the reason, when a android client is denied access it gives network communtaction issues as its reason for failing, not authentication.
    From memory these issues started when smb broke for me in 10.7.3.
    Can any one shed any light on this?
    Cheers

    bump

  • Trigger File Option in SFTP Advantco Sender Adapter

    Hi ,
    What is the purpose of Trigger file option in sender SFTP adapter?When i enabled Advance selection for source file we have this functionality.Can i use this option to delete the multiple files in the same directory instead of using File Name Mask.
    We have scenario to delete 4 files from application server in that only one file should be sent to partner and the rest should be delete from application server.
    Actual solution is to use to use script to delete the rest of the files do we have any other alternative.
    Thanks

    Hi,
    Another alternativet is to write your own customer adapter module and using java programming you can delete remaining 3 files. This is bit complex comapre to script writing but one advantage is with adapter module is that, you can provide the deteted file names with time stamp in the audit log of XI message, which will help in troublshooting if some issue happens.
    Regards,
    RK

  • Sftp batch job with password?

    Hi folks.
    We're trying to develop scripts to automate the transfer of files from various Windows machines to a Linux server.  Because the job involves moving multiple files to multiple directories, I wanted to use sftp's -B batchfile option to transfer the files instead of having to reauthenticate every time we transfer files to a different location.  However, the man page says:
    Batch mode. Reads commands from a file instead of standard input. Since this mode is intended for scripts, SFTP2 will not try to interact with the user, which means that only passwordless authentication methods will work.
    I would love to use keys to get this done but unfortunately, the type of authentication on the server is out of our control and not likely to change (it's straight password).  So, is there any way I can do this in batch mode with password authentication?  I thought about using scp but, as far as I can tell, it doesn't have great support for delivering multiple local files (in different locations) to multiple remote locations.  One would have to re-authenticate for every scp command, right?
    Any help would be appreciated.  Thanks.

    Thanks for the recommendation, Endperform, but after reading up on expect and autoexpect, I realized I'd rather not have usernames and passwords hard coded into the script.
    After much research, I think I've found a solution.  It's a little odd but the Maverick Ant library does exactly what I need it to do.  It can actually read an ssh profile, perform multiple transfers without having to re-authenticate and execute multiple remote commands without having to reauthenticate.  The native Ant libraries can't do this.  There is no sftp Ant task and the scp and sshexec tasks are lacking to say the least.
    If anyone else runs into a similar situation, I highly recommend the Maverick tool.

  • How to open a non-default port for sftp?

    My MacMini at work used to listen on port 12345 for sFTP for close to 9 months but then something (probably a power cut...) messed all things Remote up with the office setup. So I tried to reset things. It didn't work. What do you think I'm doing wrong? The MacMini is running Tiger (10.4.10). Here's what I've done so far:
    1. Drilled a hole for port 12345 on my Thomson (Alcatel SpeedTouch 780) modem/router, and disabled its Firewall and Parental Controls;
    2. In System Prefs>Sharing>Firewall I have enabled the Firewall after making sure I've added a service for port 12345;
    3. Also in System Prefs I've enabled Remote Login, to make sure the sftp daemon is running;
    4. Back on the Thomson modem/router, I've set up a service to forward port 12345 of the router to port 12345 of my MacMini (I selected it by clicking on its MAC address in the appropriate drop down menu in the modem/router config page).
    STILL: when I try to sftp to my MacMini from outside the office, I get a timeout error. Back at the MacMini, I run Network Utility and ask it to check at IP (the MacMini IP) for ports 12345 to 12345, and it doesn't report it as 'open' (it does for port 22).
    I am bummed. What am I missing? I am also 100 miles away from the office on any given day, so it's not exactly easy to pop over and try various troubleshooting things. I have to kill this once and for all next I'm at the office, some time in the weekend!
    As always, thanks, people.
    < Edited by Host >

    It sounds to me like the port forwarding is setup, so that's not the issue.
    The issue is how to change sshd to listen on port 12345 rather than port 22. However, I'm not sure that you need to.
    If you're trying to hide your server from the public, why not just setup your port forwarding to forward publicIP:12345 to privateIP:22.
    That way you connect to port 12345 from your remote location, but don't have to change the server configuration at all.
    The only reason why this wouldn't work would be if your router doesn't support different internal and external ports (e.g. it always maps to the same internal port number).
    If that's the case then you need to change launchd to listen on port 12345. How you do that depends on whether you want to move the entire SSH service to port 12345, or whether you want SSH to support 22 and 12345 at the same time.
    If the former, just edit /System/Library/LaunchDaemons/ssh.plist and change the lines:
    <key>SockServiceName</key>
    <string>ssh</string>
    to:
    <key>SockServiceName</key>
    <string>italk</string>
    (italk is the registered service for port 12345).
    Then either reboot or unload/reload the ssh.plist to make the change active.
    If you want ssh to run on both port 22 and 12345 then you should copy /System/Library/LaunchDaemons/ssh.plist to /Library/LaunchDaemons/ssh-12345.plist then make three changes to the new .plist file:
    First, change the <Label> parameter to something unique (i.e. not 'com.openssh.sshd').
    Second, remove the <Bonjour> array
    Third, edit the SockServiceName as indicated above.
    Once you've done that, reboot and you should be set.

  • Sftp is taking much time to execute

    Hi,
    I am working on SFTP .
    SFTP is working but while executing, sftp is taking 8min to execute.
    Do i need to set properties regarding time ?
    Regards,
    Divya.

    Hi,
    Use smaller polling interval for high throughput scenarios where the message size is not very large
    Regards
    Abhi

  • File not found error in SFTP channel

    Hi All,
    We are getting a "file not found error " while using a SFTP sender channel .
    Our Scenario :
    We are using SFTP as the source adapter .Presently we are using  two nodes for load balancing for all the sender channels.
    One of the node's of the  SFTP channel is picking the file , while the other node at the same time is throwing a "File not found error".
    The file is being picked and is placed at the target, but the channels are in error state as one of the nodes is in error state.
    Please let me know, if we did any mistake while configuring the adapter.
    Thanks,
    Yamunan

    Hi,
    Could you please check if you have provided right path in your sender communication channel...to pick the file from...
    Regards,
    Naveen.

  • [Solved for me]Distinguishing SSH and SFTP (for QoS purposes)

    Hi there,
    I'm thinking about shutting down the FTP on my homeserver and use SFTP instead. There is only one thing I couldn't solve so far: In my router I have QoS-rules that make FTP low priority traffic so my normal activities don't get affected by the file transfers. I would like to have the same setup for the SFTP. Now the problem is this: SFTP and SSH are both coming from the same ssh server, listening on port 22. So there is no way of distinguishing them on a ip/port basis. Is there any way of distinguishing SFTP and SSH? Like using iptables to tag one of them and then doing QoS based on the tag or something along those lines? I don't want to slow down my ssh-connections together with the sftp. If anyone has an idea how to accomplish this I would be really glad to hear about it.
    Thanks in advance
    seiichiro0185
    Last edited by seiichiro0185 (2010-08-22 11:27:32)

    briest wrote:Well, a simple, though definitely not bulletproof solution: define multiple ports in sshd_config, then use one of them for sftp, and another for ssh?
    Thanks for this hint, I didn't know that ssh could listen on multiple ports. Its not totally bulletproof, but good enough for my case. The only people who will have access to the server are trustworthy and won't fiddle with the settings to circumvent my restrictions.
    Thanks to all of you for your suggestions.

  • How to delete zip file in sftp server

    Hi Gurus,
    I am having one .zip file with data files inside on the sftp server. Can you please how to delete the .zip files in the sftp server. I am able to delete normal files by using 'rm' on sftp.
    And one more request my sftp is prompting for the password everytime, then i need to enter the password manually. Can any one suggest how to write in shell script to accept that.
    Thanks in advance.
    Regards
    Nagendra

    You might want to look into user equivalence and configure a certificate for ssh so it does not prompt for a password.
    It will also allow you to use sftp without a prompt for a password.
    On the server side:
    Edit /etc/ssh/sshd_config and remove the # from the following:
    RSAAuthentication yes
    PubkeyAuthentication yes
    AuthorizedKeysFile .ssh/authorized_keys
    Then restart the ssh server:
    /etc/init.d/sshd restart
    Login as the user for whom this is for:
    su - <username>
    mkdir .ssh
    chmod 700 .ssh
    On the client side:
    Run the following command:
    ssh-keygen -t rsa (omit password)
    Then use the following to copy the public key from the client to the
    corresponding login .ssh directory on the server side;
    scp .ssh/id_rsa.pub username@remote_host:.ssh/authorized_keys

  • Can't establish a sftp connection with the finder

    Hi, I'm trying to establish a sftp connection with the finder (using the "Connect to server" feature) between my (recently purchased) Mac Mini (mid 2011: i5, 2.3 GHz, 2 GB, running 10.7.3) and a Debian Testing box and I can't, I get the following error:
    'There was a problem connecting to the server "ip.address"
    This file server will not allow any additional users to log on. Try to connect again later.'
    However if I try establishing a connection from the terminal (either ssh or sftp) it works flawlessly:
    SSH:
    victoria:~ RonIn$ ssh [email protected]
    [email protected]'s password:
    Linux clementine 3.0.0-1-486 #1 Sat Aug 27 15:56:48 UTC 2011 i686
    The programs included with the Debian GNU/Linux system are free software;
    the exact distribution terms for each program are described in the
    individual files in /usr/share/doc/*/copyright.
    Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
    permitted by applicable law.
    You have new mail.
    Last login: Sat Apr 28 21:52:18 2012 from ukamy.local
    ronin@clementine:~$
    SFTP:
    victoria:~ RonIn$ sftp [email protected]
    [email protected]'s password:
    Connected to ip.address.
    sftp>
    I've searched for a fix or alternative on the internet and I haven't found one that works; The one that keeps coming up is to try: "ftps" as the protocol instead of "sftp" with the remaining information the same (it doesn't work, it gets the same error message afterwards).
    The IP address and login information works (corroborated by the fact that I can log in from the terminal from the Mac Mini) so the only issue is with the finder capabilities for establishing the connection. I have looked for apple related documentation or How Tos but I haven't found anything useful.
    I don't want to use any third party app or tweak because of the sensitive information that is going to be transfered, I would like to be using strictly the tools from the OS.
    If you need any more information please let me know, any help is deeply appreciated.

    I have the same issue although i kind of fixed it. I have two admin accounts and one of the account's safari did the same thing as yours, except, it was the startpage and everypage i tried to visit. I reseted safari, as in the erase all data safari in the toolbar, safari-Reset Safari... But safari still didn't work. I logged out and went to my other account and opened safari. Now it works fine on both accounts. This meant safari had to logout before actually working better. I have this a few times these days.

  • How can I set up SFTP into a Mac if I do not have access to its network's router?

    Title says it all. My Mac is at work. I cannot change the work's router settings. Is there a way to set up SFTP access to the Mac or am I out of luck?

    data.
    At least your query seems to get data where MODIFIED_BY IS NULL, doesn't it?
    So if the reccount is>0 there is a reason to inform your employees.
    Bye, Olaf.
    Olaf Doschke - TMN Systemberatung GmbH
    http://www.tmn-systemberatung.de

  • Error while putting file in sftp location.

    Hi All,
    One of my BPEL process is using flow activity which has 5 flow in parallel, each flow has sftp invoke and we are writing file (put) to SFTP server. sometime bpel process is failing with below error message.
    Is someone has any idea to remove this error?
    Thanks in Advance.
    </part><part name="summary"><summary>file:/gembin/oracle/product/10.1.3/SOA/bpel/domains/gemptm/tmp/.bpel_SyncPlanDataASCPReqABCS_1.0_5678626ccda718f92a73c5656.tmp/plPutBookOrderTransit.wsdl [ Put_ptt::Put(Root-Element) ] - WSIF JCA Execute of operation 'Put' failed due to: Error sending file to FTP Server.
    Unable to send file to server. [Caused by: Unexpected termination: Connection reset]
    ; nested exception is:
    ORABPEL-11429
    Error sending file to FTP Server.
    Unable to send file to server. [Caused by: Unexpected termination: Connection reset]
    Please ensure 1. Specified remote output Dir has write permission 2. Output filename has not exceeded the max chararters allowed by the OS and 3. Remote File System has enough space.

    Hi,
    I have got the same error, and late figured out why it is coming...actually i am appending the records to a file in remote server, the file was kept open by someone on their Desktop. Later after they closed the file, the error is not coming again.
    Hope this helps someone.
    Thanks,
    N

  • FTP to SFTP.

    Hi,
    My application is using ftp to connect to the server. but now it is going to change to sftp. For that I am not able to get what are the things in need to change in my ftp program to make it support for sftp. The following is the ftpbean class and the methods of the class are used by other classes. sftp is already installed and the environment is ready now. but I am not able to proceed where to modify the java..Please help.
    import java.beans.PropertyChangeListener;
    import java.beans.PropertyChangeSupport;
    import java.io.*;
    import java.net.Socket;
    import java.net.ServerSocket;
    import java.util.StringTokenizer;
    import java.util.Vector;
    public class FtpBean
    private String server = ""; // server name
    private String user = ""; // user name
    private String replyMessage = ""; // reply message from server
    private String reply = ""; // reply to the command
    private Socket socket; // Socket for FTP connection
    private BufferedReader in; // Input for FTP connection
    private PrintWriter out; // Output for FTP connection
    private int port = 21; // FTP port number, default 21
    private boolean passive = true; // Passive mode transfer, default true
    // Needed for thread safety
    private int[] lock = new int[0]; // For synchronized locking
    private boolean acquired = false; // Count the number of acquire
    private Vector threadSpool = new Vector(); // Spool for the waiting threads
    // Needed for some Visual tools
    private PropertyChangeSupport pcs; // PropertyChangeSupport for visual tools
    final private boolean DEBUG = false; // True to turn on debug mode
    * Constructor
    public FtpBean()
    pcs = new PropertyChangeSupport(this);
    * Add PropertyChangeListener
    public void addPropertyChangeListener(PropertyChangeListener listener)
    pcs.addPropertyChangeListener(listener);
    * removePropertyChangeListener
    public void removePropertyChangeListener(PropertyChangeListener listener)
    pcs.removePropertyChangeListener(listener);
    * Connect to FTP server and login.
    * @param server Name of server
    * @param user User name for login
    * @param password Password for login
    * @exception FtpException if a ftp error occur (eg. Login fail in this case).
    * @exception IOException if an I/O error occur
    public void ftpConnect(String server, String user, String password)
    throws IOException, FtpException
    if (DEBUG) // Debug message
    System.out.println("FtpBean: Connecting to server " + server);
    acquire(); // Acquire the object
    // Set server name & user name
    setServerName(server);
    setUserName(user);
    try {
    // Create socket, get input & output stream
    socket = new Socket(server, port);
    in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    out = new PrintWriter(socket.getOutputStream(), true);
    // Read reply code when get connected
    getRespond();
    if (DEBUG) // Debug message
    System.out.println("FtpBean: Connected");
    // Login
    ftpLogin(user, password); // check if login success
    finally {
    release(); // Release the object
    * Close FTP connection.
    * @exception IOException if an I/O error occur
    * @exception FtpException if a ftp error occur
    public void close()
    throws IOException, FtpException
    if (out == null)
    return;
    acquire(); // Acquire the object
    try {
    ftpCommand("QUIT");
    if (!reply.startsWith("221"))
    throw new FtpException(reply);
    closeSocket();
    // Set server name & user name to ""
    setServerName("");
    setUserName("");
    finally {
    release(); // Release the object
    * Delete a file at the FTP server.
    * @param filename Name of the file to be deleted.
    * @exception FtpException if a ftp error occur. (eg. no such file in this case)
    * @exception IOException if an I/O error occur.
    public void fileDelete(String fileName)
    throws IOException, FtpException
    acquire(); // Acquire the object
    try {
    ftpCommand("DELE " + fileName);
    if (!reply.startsWith("250"))
    throw new FtpException(reply);
    finally {
    release(); // Release the object
    * Rename a file at the FTP server.
    * @param oldFileName The name of the file to be renamed
    * @param newFileName The new name of the file
    * @exception FtpException if a ftp error occur. (eg. A file named the new file name already in this case.)
    * @exception IOException if an I/O error occur.
    public void fileRename(String oldFileName, String newFileName)
    throws IOException, FtpException
    acquire(); // Acquire this object
    try {
    ftpCommand("RNFR " + oldFileName);
    if (!reply.startsWith("350"))
    throw new FtpException(reply);
    ftpCommand("RNTO " + newFileName);
    if (!reply.startsWith("250"))
    throw new FtpException(reply);
    finally {
    release(); // Release the object
    private boolean isSameSystem()
    throws IOException, FtpException
    String sysType = getSystemType();
    return (sysType.toUpperCase().indexOf("WINDOWS") < 0);
    * @param ftpFile Name of file to be get from the ftp server, can be in full path.
    * @param localFile File name of local file
    * @exception FtpException if a ftp error occur. (eg. No such file in this case)
    * @exception IOException if an I/O error occur.
    * @see FtpObserver
    public void getAsciiFile(String ftpFile, String localFile)
    throws IOException, FtpException
    getAsciiFile(ftpFile, localFile, null);
    * @param ftpFile Name of file to be get from the ftp server, can be in full path.
    * @param localFile File name of local file
    * @param observer The FtpObserver which monitor this downloading progress
    * @exception FtpException if a ftp error occur. (eg. No such file in this case)
    * @exception IOException if an I/O error occur.
    * @see FtpObserver
    public void getAsciiFile(String ftpFile, String localFile, FtpObserver observer)
    throws IOException, FtpException
    if (isSameSystem()) {
    getBinaryFile(ftpFile, localFile, observer);
    return;
    acquire(); // Acquire the object
    setTransferType(true); // Set transfer type to ascii
    Socket sock = null;
    try {
    sock = getDataSocket("RETR " + ftpFile, 0);
    // Read bytes from server and write to file.
    BufferedReader din = new BufferedReader(new InputStreamReader(sock.getInputStream()));
    PrintWriter dout = new PrintWriter(new BufferedWriter(new FileWriter(localFile)));
    char[] cbuf = new char[2048];
    int n;
    while ((n = din.read(cbuf, 0, cbuf.length)) != -1) {
    if (skipLineSepFilter())
    dout.write(cbuf, 0, n);
    else {
    // filter DOS line-sep to UNIX line-sep
    String data = filterLineSep(cbuf, n);
    dout.write(data, 0, data.length());
    if (observer != null)
    observer.byteRead(n);
    String data = null;
    while ((data = din.readLine()) != null) {
    dout.println(data);
    if (observer != null)
    observer.byteRead(data.length() + 1);
    din.close();
    dout.close();
    sock.close();
    getRespond();
    if (!reply.startsWith("226"))
    throw new FtpException(reply); // transfer incomplete
    finally {
    release(); // Release the object
    public void putAsciiFile(String localFile, String remoteFile, FtpObserver observer)
    throws IOException, FtpException
    acquire(); // Acquire the object
    setTransferType(true);
    // if file is to be transferred to MF, without slash, exec quote site cmd
    if (!remoteFile.startsWith("/"))
    setQuoteSite();
    Socket sock = null;
    try {
    // Read bytes from local file and write to a server.
    BufferedReader din = new BufferedReader(new FileReader(localFile));
    sock = getDataSocket("STOR " + remoteFile, 0);
    PrintWriter dout = new PrintWriter(new BufferedWriter(new OutputStreamWriter(sock.getOutputStream())));
    String data = null;
    while ((data = din.readLine()) != null) {
    //dout.println(data);
    dout.write(data);
    dout.write("\r\n");
    if (observer != null)
    observer.byteWrite(data.length() + 1);
    din.close();
    dout.close();
    sock.close();
    getRespond();
    if (DEBUG) // Debug message
    System.out.println("FtpBean: Reply is " + reply);
    putAsciiFile()
    Changed manner of checking if transfer is complete by checking the
    string Transfer Complete in the reply.
    For UNIX: Reply is 226 Transfer complete.
    For MF: Reply is 250 Transfer completed successfully.
    //if (!reply.startsWith("226"))
    int m = 0;
    if ((m = reply.indexOf("Transfer complete")) < 0)
    throw new FtpException(reply); // transfer incomplete
    finally {
    release(); // Release the object
    * Read file from ftp server and write to a file in local hard disk.
    * This method is much faster than those method which return a byte array<br>
    * if the network is fast enough.<br>
    * <br>Remark:<br>
    * Cannot be used in unsigned applet.
    * @param ftpFile Name of file to be get from the ftp server, can be in full path.
    * @param localFile Name of local file to be write, can be in full path.
    * @exception FtpException if a ftp error occur. (eg. No such file in this case)
    * @exception IOException if an I/O error occur.
    public void getBinaryFile(String ftpFile, String localFile)
    throws IOException, FtpException
    getBinaryFile(ftpFile, localFile, 0, null);
    * Read file from ftp server and write to a file in local hard disk.
    * This method is much faster than those method which return a byte array<br>
    * if the network is fast enough.<br>
    * <br>Remark:<br>
    * Cannot be used in unsigned applet.
    * @param ftpFile Name of file to be get from the ftp server, can be in full path.
    * @param localFile Name of local file to be write, can be in full path.
    * @param restart Restarting point
    * @exception FtpException if a ftp error occur. (eg. No such file in this case)
    * @exception IOException if an I/O error occur.
    public void getBinaryFile(String ftpFile, String localFile, long restart)
    throws IOException, FtpException
    getBinaryFile(ftpFile, localFile, restart, null);
    * Read file from ftp server and write to a file in local hard disk.
    * This method is much faster than those method which return a byte array<br>
    * if the network is fast enough.<br>
    * <br>Remark:<br>
    * Cannot be used in unsigned applet.
    * @param ftpFile Name of file to be get from the ftp server, can be in full path.
    * @param localFile Name of local file to be write, can be in full path.
    * @param observer The FtpObserver which monitor this downloading progress
    * @exception FtpException if a ftp error occur. (eg. No such file in this case)
    * @exception IOException if an I/O error occur.
    * @see FtpObserver
    public void getBinaryFile(String ftpFile, String localFile, FtpObserver observer)
    throws IOException, FtpException
    getBinaryFile(ftpFile, localFile, 0, observer);
    * Read from a ftp file and restart at a specific point.
    * This method is much faster than those method which return a byte array<br>
    * if the network is fast enough.<br>
    * Remark:<br>
    * Cannot be used in unsigned applet.
    * @param ftpFile Name of file to be get from the ftp server, can be in full path.
    * @param localFile File name of local file
    * @param restart Restarting point, ignored if equal or less than zero.
    * @param observer The FtpObserver which monitor this downloading progress
    * @exception FtpException if a ftp error occur. (eg. No such file in this case)
    * @exception IOException if an I/O error occur.
    * @see FtpObserver
    public void getBinaryFile(String ftpFile, String localFile, long restart, FtpObserver observer)
    throws IOException, FtpException
    acquire(); // Acquire the object
    setTransferType(false); // Set transfer type to binary
    Socket sock = null;
    try {
    sock = getDataSocket("RETR " + ftpFile, restart);
    // Read bytes from server and write to file.
    BufferedInputStream din = new BufferedInputStream(sock.getInputStream());
    RandomAccessFile dout = new RandomAccessFile(localFile, "rw");
    dout.seek(restart);
    byte[] data = new byte[1024];
    int n;
    while ((n = din.read(data)) != -1) {
    dout.write(data, 0, n);
    if (observer != null)
    observer.byteRead(n);
    din.close();
    dout.close();
    sock.close();
    getRespond();
    if (!reply.startsWith("226"))
    throw new FtpException(reply); // transfer incomplete
    finally {
    release(); // Release the object
    * Read a file from local hard disk and write to the server.
    * <br>Remark:<br>
    * <br>Cannot be used in unsigned applet.
    * @param local_file Name of local file, can be in full path.
    * @param remoteFile Name of file in the ftp server, can be in full path.
    * @exception FtpException if a ftp error occur. (eg. permission denied)
    * @exception IOException if an I/O error occur.
    public void putBinaryFile(String localFile, String remoteFile)
    throws IOException, FtpException
    putBinaryFile(localFile, remoteFile, 0, null);
    * Read a file from local hard disk and write to the server.
    * <br>Remark:<br>
    * <br>Cannot be used in unsigned applet.
    * @param localFile Name of local file, can be in full path.
    * @param remoteFile Name of file in the ftp server, can be in full path.
    * @param observer The FtpObserver which monitor this uploading progress.
    * @exception FtpException if a ftp error occur. (eg. permission denied)
    * @exception IOException if an I/O error occur.
    public void putBinaryFile(String localFile, String remoteFile, FtpObserver observer)
    throws IOException, FtpException
    putBinaryFile(localFile, remoteFile, 0, observer);
    * Read a file from local hard disk and write to the server with restarting point.
    * Remark:<br>
    * Cannot be used in unsigned applet.
    * @param localFile Name of local file, can be in full path.
    * @param remoteFile Name of file in the ftp server, can be in full path.
    * @param restart The restarting point, ignored if less than or greater than zero.
    * @exception FtpException if a ftp error occur. (eg. permission denied)
    * @exception IOException if an I/O error occur.
    public void putBinaryFile(String localFile, String remoteFile, long restart)
    throws IOException, FtpException
    putBinaryFile(localFile, remoteFile, restart, null);
    * Read a file from local hard disk and write to the server with restarting point.
    * Remark:<br>
    * Cannot be used in unsigned applet.
    * @param localFile Name of local file, can be in full path.
    * @param remoteFile Name of file in the ftp server, can be in full path.
    * @param observer The FtpObserver which monitor this uploading progress
    * @exception FtpException if a ftp error occur. (eg. permission denied)
    * @exception IOException if an I/O error occur.
    public void putBinaryFile(String localFile, String remoteFile, long restart, FtpObserver observer)
    throws IOException, FtpException
    acquire(); // Acquire the object
    setTransferType(false);
    Socket sock = null;
    try {
    RandomAccessFile din = new RandomAccessFile(localFile, "r");
    sock = getDataSocket("STOR " + remoteFile, restart);
    if (restart > 0)
    din.seek(restart);
    DataOutputStream dout = new DataOutputStream(sock.getOutputStream());
    byte[] data = new byte[1024];
    int n;
    while ((n = din.read(data)) != -1) {
    dout.write(data, 0, n);
    if (observer != null)
    observer.byteWrite(n);
    din.close();
    dout.close();
    sock.close();
    getRespond();
    putBinaryFile()
    Changed manner of checking if transfer is complete by checking the
    string Transfer Complete in the reply.
    For UNIX: Reply is 226 Transfer complete.
    For MF: Reply is 250 Transfer completed successfully.
    //if (!reply.startsWith("226"))
    int m = 0;
    if ((m = reply.indexOf("Transfer complete")) < 0)
    throw new FtpException(reply); // transfer incomplete
    finally {
    release(); // Release the object
    * Get current directory name.
    * @return The name of the current directory.
    * @exception FtpException if a ftp error occur.
    * @exception IOException if an I/O error occur.
    public String getDirectory()
    throws IOException, FtpException
    acquire(); // Acquire the object
    try {
    ftpCommand("PWD");
    if (!reply.startsWith("257"))
    throw new FtpException(reply);
    int first = reply.indexOf("\"");
    int last = reply.lastIndexOf("\"");
    return reply.substring(first + 1, last);
    finally {
    release(); // Release the object
    * Change directory.
    * @param directory Name of directory
    * @exception FtpException if a ftp error occur. (eg. permission denied in this case)
    * @exception IOException if an I/O error occur.
    public void setDirectory(String directory)
    throws IOException, FtpException
    acquire(); // Acquire the object
    try {
    ftpCommand("CWD " + directory);
    if (!reply.startsWith("250"))
    throw new FtpException(reply);
    finally {
    release(); // Release the object
    * Change to parent directory.
    * @exception FtpException if a ftp error occur. (eg. permission denied in this case)
    * @exception IOException if an I/O error occur.
    public void toParentDirectory()
    throws IOException, FtpException
    acquire(); // Acquire the object
    try {
    ftpCommand("CDUP");
    if (!reply.startsWith("250"))
    throw new FtpException(reply);
    finally {
    release(); // Release the object
    * Get the content of current directory
    * @return A FtpListResult object, return null if it is not connected.
    * @exception FtpException if a ftp error occur. (eg. permission denied in this case)
    * @exception IOException if an I/O error occur.
    * @see FtpListResult
    public FtpListResult getDirectoryContent()
    throws IOException, FtpException
    String strList = getDirectoryContentAsString();
    FtpListResult ftpList = new FtpListResult();
    ftpList.parseList(strList, getSystemType());
    return ftpList;
    * Get the content of current directory.
    * @return A list of directories, files and links in the current directory.
    * @exception FtpException if a ftp error occur. (eg. permission denied in this case)
    * @exception IOException if an I/O error occur.
    public String getDirectoryContentAsString()
    throws IOException, FtpException
    StringBuffer list = new StringBuffer(""); // Directory list
    Socket sock = null; // Socket to establish data connection
    acquire(); // Acquire the object
    try {
    // get DataSocket for the LIST command.
    // As no restarting point, send 0.
    sock = getDataSocket("LIST", 0);
    BufferedReader din = new BufferedReader(new InputStreamReader(sock.getInputStream()));
    // Read bytes from server.
    String line;
    while ((line = din.readLine()) != null)
    list.append(line).append("\n");
    din.close();
    sock.close();
    getRespond();
    if (!reply.startsWith("226"))
    throw new FtpException(reply);
    finally {
    release(); // Release the object
    return list.toString();
    * Make a directory in the server.
    * @param directory The name of directory to be made.
    * @exception FtpException if a ftp error occur. (eg. permission denied in this case)
    * @exception IOException if an I/O error occur.
    public void makeDirectory(String directory)
    throws IOException, FtpException
    acquire(); // Acquire the object
    try {
    ftpCommand("MKD " + directory);
    if (!reply.startsWith("257"))
    throw new FtpException(reply);
    finally {
    release(); // Release the object
    * Remove a directory in the server
    * @param directory The name of directory to be removed
    * @exception FtpException if a ftp error occur. (eg. permission denied in this case)
    * @exception IOException if an I/O error occur.
    public void removeDirectory(String directory)
    throws IOException, FtpException
    acquire(); // Acquire the object
    try {
    ftpCommand("RMD " + directory);
    if (!reply.startsWith("250"))
    throw new FtpException(reply);
    finally {
    release(); // Release the object
    * Execute a command using ftp.
    * e.g. chmod 700 file
    * @param exec The command to execute.
    * @exception FtpException if a ftp error occur. (eg. command not understood)
    * @exception IOException if an I/O error occur.
    public void execute(String exec)
    throws IOException, FtpException
    acquire(); // Acquire the object
    try {
    ftpCommand("SITE " + exec);
    if (!reply.startsWith("200"))
    throw new FtpException(reply);
    finally {
    release(); // Release the object
    private String _ftpSystemType = null;
    * Get the type of operating system of the server.
    * Return null if it is not currently connected to any ftp server.
    * @return Name of the operating system.
    public String getSystemType()
    throws IOException, FtpException
    if (_ftpSystemType != null)
    return _ftpSystemType;
    acquire(); // Acquire the object
    try {
    ftpCommand("SYST");
    if (!reply.startsWith("215"))
    throw new FtpException(reply);
    _ftpSystemType = reply.substring(4);
    return _ftpSystemType;
    finally {
    release(); // Release the object
    * Return the port number
    public int getPort()
    return port;
    * Set port number if the port number of ftp is not 21
    public void setPort(int port)
    acquire(); // Acquire the object
    pcs.firePropertyChange("port", new Integer(this.port), new Integer(port));
    this.port = port;
    release(); // Release the object
    * Return the server name. Return "" if it is not connected to any server.
    public String getServerName()
    return server;
    * Return the user name. Return "" if it is not connected to any server.
    public String getUserName()
    return user;
    * Get reply of the last command.
    * @return Reply of the last comomand<br>for example: 250 CWD command successful
    public String getReply()
    return reply;
    * Get reply message of the last command.
    * @return Reply message of the last command<br>for example:<br>
    * 250-Please read the file README<br>
    * 250-it was last modified on Wed Feb 10 21:51:00 1999 - 268 days ago
    public String getReplyMessage()
    return replyMessage;
    * Return true if it is using passive transfer mode.
    public boolean isPassiveModeTransfer()
    return passive;
    * Set passive transfer mode. Default is true.
    * @param passive Using passive transfer if true.
    public void setPassiveModeTransfer(boolean passive)
    acquire(); // Acquire the object
    pcs.firePropertyChange("passiveModeTransfer", new Boolean(this.passive), new Boolean(passive));
    this.passive = passive;
    if (DEBUG) // debug message
    System.out.println("FtpBean: Set passive transfer - " + passive);
    release(); // Release the object
    * Close the Socket, input and output stream
    private void closeSocket()
    throws IOException
    _ftpSystemType = null;
    in.close();
    out.close();
    socket.close();
    in = null;
    out = null;
    socket = null;
    * Read the respond message from the server's inputstream and assign to replyMessage
    private void getRespond()
    throws IOException
    String line = "";
    String replyMessage = "";
    while (true) {
    // Problem.....
    line = in.readLine();
    if (!checkReply(line))
    break;
    replyMessage = replyMessage.concat(line).concat("\n");
    setReplyMessage(replyMessage);
    setReply(line);
    * Login to server, using FTP commands "USER" and "PASS"
    * @param user FTP username
    * @param password FTP Password
    private void ftpLogin(String user, String password)
    throws IOException, FtpException
    ftpCommand("USER " + user); // send user name
    ftpCommand("PASS " + password); // send password
    if (!reply.startsWith("230")) {
    closeSocket();
    throw new FtpException(reply);
    * Send FTP command to the server.
    * @param command The command to be sent
    private void ftpCommand(String command)
    throws IOException
    if (DEBUG) {  // Debug message
    if (command.startsWith("PASS"))
    System.out.println("FtpBean: Send password");
    else
    System.out.println("FtpBean: Send command \"" + command + "\"");
    out.print(command + "\r\n"); // Send command
    out.flush();
    getRespond();
    * Establish data connection for transfer
    private Socket getDataSocket(String command, long restart)
    throws IOException, FtpException
    Socket sock = null;
    ServerSocket ssock = null;
    // Establish data conncetion using passive or active mode.
    if (passive)
    sock = getPassiveDataSocket();
    else
    ssock = getActiveDataSocket();
    // Send the restart command if it is greater than zero
    if (restart > 0) {
    ftpCommand("REST " + restart);
    if (!reply.startsWith("350"))
    throw new FtpException(reply);
    // Send commands like LIST, RETR and STOR
    // These commands will return 125 or 150 when success.
    ftpCommand(command);
    if (!(reply.startsWith("125") || reply.startsWith("150")))
    throw new FtpException(reply); // command file
    // Get Socket object for active mode.
    if (!passive)
    sock = ssock.accept();
    return sock;
    * Establish data connection in passive mode using "PASV" command
    * Change the server to passive mode.
    * by the command "PASV", it will return its address
    * and port number that it will listen to.
    * Create a Socket object to that address and port number.
    * Then return the Socket object.
    private Socket getPassiveDataSocket()
    throws IOException, FtpException
    ftpCommand("PASV");
    if (!reply.startsWith("227"))
    throw new FtpException(reply);
    // array that holds the outputed address and port number.
    String[] address = new String[6];
    // put the 'reply' to the array 'address'
    StringTokenizer t = new StringTokenizer(reply, ",");
    for (int i = 0; i < 6; i++)
    address[i] = t.nextToken();
    // Get port number.
    // Erase all other characters except the port number
    // which is at the beginning of the string
    String lastPort = "";
    int num = 3;
    if (address[5].length() < 3)
    num = address[5].length();
    for (int i = 0; i < num; i++) {
    if (Character.isDigit(address[5].charAt(i)))
    lastPort = lastPort + address[5].charAt(i);
    // assign last port number to address[5]
    address[5] = lastPort;
    // Get the port number
    // Left shift the first number by 8
    int newPort = (Integer.parseInt(address[4]) << 8) + Integer.parseInt(address[5]);
    // Create a new socket object
    Socket sock = new Socket(getServerName(), newPort);
    return sock;
    * Establish data connection in active mode using "PORT" command.
    * It create a ServerSocket object to listen for a port number in local machine.
    * Use port command to tell the server which port the local machine is listenning.
    * Return the ServerSocket object.
    private ServerSocket getActiveDataSocket()
    throws IOException, FtpException
    int[] portNumbers = new int[6]; // Array that contains
    // Get ip address of local machine. ip address and port numbers
    String localAddr = socket.getLocalAddress().getHostAddress();
    // Assign the ip address of local machine to the array.
    StringTokenizer st = new StringTokenizer(localAddr, ".");
    for (int i = 0; i < 4; i++)
    portNumbers[i] = Integer.parseInt(st.nextToken());
    ServerSocket ssocket = new ServerSocket(0); // ServerSocket to listen to a random free port number
    int localPort = ssocket.getLocalPort(); // The port number it is listenning to
    // Assign port numbers the array
    portNumbers[4] = ((localPort & 0xff00) >> 8);
    portNumbers[5] = (localPort & 0x00ff);
    // Send "PORT" command to s

    You would have to pick a library to do that. There are several commercial libraries. Out of the open source ones, the most mature one seems to be Ganymed SSH-2.

Maybe you are looking for

  • My USB Port does not Find my I POD

    My USB port does not find my I POD. I have Installed all th elatest software.

  • How to update VBEP-AESKD (sales order-schedule lines) through a BAPI?

    Hello experts, I have the rquirement to change the fields AESKD and *SERNR *in VBEP. BAPI_SALESORDER_CHANGE seems not to provide the facility to deal with this field. Question is: How do I update fields that are not availabe in the BAPI (SCHEDULE_LIN

  • How do I create so...

    Helloo all, I dont know what do I call this effect. But I wantted to try this effect. Can you guide me how do i create so: https://www.facebook.com/photo.php?fbid=377033712385846&set=a.234176606671558.52168.229229 803832905&type=1&theater

  • SAP Netweaver Developer Studio Updatesite problem

    Hi, I have installed SAP Netweaver Developer Studio CE 7.1 SP09 in my desktop. I am trying to connect to local update site. I am getting the below mentioned error.     Network connection problems encountered during search.     Unable to access "http:

  • CS6 Opening Question

    Everytime I open CS6 it always opens with the same 5 pictures. Is there a way to have it open without those 5 pictures or any pictures for that matter? Thanks in advance for your help. Russ