Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the <a href="http://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClient.html#changeWorkingDirectory%28java.lang.String%29" rel="nofollow"><code>changeCurrentWorkingDirectory()</code></a> method to change to the desired directory. Once you're in there, you can write the file using <a href="http://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClient.html#storeFile%28java.lang.String,%20java.io.InputStream%29" rel="nofollow"><code>storeFile</code></a> just like before.</p> <p><code>changeCurrentWorkingDirectory</code> returns true if the directory change was successful, otherwise it returns false. It takes a string which interpreted as the directory path. If the path starts with a slash, it's interpreted as absolute path starting at the ftproot directory. Otherwise it's interpreted as relative path.</p> <p>Revised code could look something like this:</p> <pre><code>FTPClient client = new FTPClient(); FileInputStream fis = null; try { client.connect(serverip); client.login("user, pass); client.setFileType(FTPClient.BINARY_FILE_TYPE); // change directory to serverip/file/ if (client.changeWorkingDirectory("/file")) { // Create an InputStream of the file to be uploaded String filename = Shared.saveLocation + Shared.saveAs; fis = new FileInputStream(filename); // Store file to server client.storeFile(Shared.saveAs, fis); } client.logout(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fis != null) { fis.close(); } client.disconnect(); } catch (IOException e) { e.printStackTrace(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload