Upload directory to specified FTP server without retries.

@param ftpServer
@param username
@param password
@param sourceDirectoryPath
@param targetDirectoryPath
@return Boolean to indicate whether uploading is successful.
184549
protected boolean uploadDirectory(final String ftpServer, final String username, final String password,
                                      final String sourceDirectoryPath, final String targetDirectoryPath) {
        log.debug("FTP username: " + username);
        try {
            final FTPClient ftpClient = getFTPClient(ftpServer, username, password);

            log.info(String.format(UPLOAD_DIR_START, sourceDirectoryPath, targetDirectoryPath));
            uploadDirectory(ftpClient, sourceDirectoryPath, targetDirectoryPath, "");
            log.info(String.format(UPLOAD_DIR_FINISH, sourceDirectoryPath, targetDirectoryPath));

            ftpClient.disconnect();
            return true;
        } catch (Exception e) {
            log.debug(e);
            log.error(String.format(UPLOAD_DIR_FAILURE, sourceDirectoryPath, targetDirectoryPath));
        }

        return false;
    }
900271
public function upload($source, $path, $override = false)
    {
        $fd = fopen($source, "rb");
        $writeMode = ($override===true) ? WriteMode::force() : WriteMode::add();
        $metadata = $this->dropbox->uploadFile($this->pathRoot.$path, $writeMode, $fd);
        fclose($fd);

        return !is_null($metadata);
    }
500923
private FTPClient connect() throws IOException {
    FTPClient client = null;
    Configuration conf = getConf();
    String host = conf.get("fs.ftp.host");
    int port = conf.getInt("fs.ftp.host.port", FTP.DEFAULT_PORT);
    String user = conf.get("fs.ftp.user." + host);
    String password = conf.get("fs.ftp.password." + host);
    client = new FTPClient();
    client.connect(host, port);
    int reply = client.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
      throw new IOException("Server - " + host
          + " refused connection on port - " + port);
    } else if (client.login(user, password)) {
      client.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE);
      client.setFileType(FTP.BINARY_FILE_TYPE);
      client.setBufferSize(DEFAULT_BUFFER_SIZE);
    } else {
      throw new IOException("Login failed on server - " + host + ", port - "
          + port);
    }

    return client;
  }
456874
public function getAll($source_directory, $target_directory, $mode = FTP_BINARY)
    {
        if ($source_directory != ".") { 
            if ($this->ftp->chdir($source_directory) == false) { 
                throw new FtpException("Unable to change directory: ".$source_directory);
            }

            if (!(is_dir($source_directory))) {
                mkdir($source_directory);
	    }

            chdir($source_directory); 
        } 

        $contents = $this->ftp->nlist(".");

        foreach ($contents as $file) { 
            if ($file == '.' || $file == '..') {
                continue;
	    }

            $this->ftp->get($target_directory."/".$file, $file, $mode);
        }

        $this->ftp->chdir(".."); 
        chdir(".."); 

        return $this;
    }
1043076
File getTargetDirectory( File sourceFile, File sourceBaseDir, File targetBaseDir )
        throws MojoExecutionException, MojoFailureException
    {
        String filePath;
        String tempPath;
        try
        {
            filePath = sourceFile.getParentFile().getCanonicalPath();
            tempPath = sourceBaseDir.getCanonicalPath();
        }
        catch ( IOException e )
        {
            throw new MojoExecutionException( "Error getting canonical path", e );
        }

        if ( !filePath.startsWith( tempPath ) )
        {
            throw new MojoFailureException( "File " + sourceFile
                + " is expected to be somewhere under the following directory: " + tempPath );
        }

        File targetDir = new File( targetBaseDir, filePath.substring( tempPath.length() ) );
        return targetDir;
    }
1254943
public void setDirectoryUser(String userName, String password){
        this.authData = generateDirectoryAuthData(userName, password);
        if(getStatus().isConnected()){
            ErrorCode ec = sendConnectProtocol(this.getConnectTimeOut());
            if(ErrorCode.SESSION_EXPIRED.equals(ec)){
                LOGGER.info("Session Expired, cleanup the client session.");
                closeSession();
            } else if(! ErrorCode.OK.equals(ec)){
                reopenSession();
            }
        }
    }
712156
public function save($targetDir, $gzip = false)
    {
        $this->initializeFileHandler();
        $filename = realpath($targetDir) . '/' . basename($this->getLoc());
        $sitemapFile = fopen($filename, 'w+');
        $structureXml = $this->getStructureXml();

        // since header may contain namespaces which may get added when adding URLs
        // we can't prepare the header beforehand, so here we just take it and add to the beginning of the file
        $header = substr($structureXml, 0, strpos($structureXml, 'URLS</urlset>'));
        fwrite($sitemapFile, $header);

        // append body file to sitemap file (after the header)
        fflush($this->bodyFile);
        fseek($this->bodyFile, 0);

        while (!feof($this->bodyFile)) {
            fwrite($sitemapFile, fread($this->bodyFile, 65536));
        }
        fwrite($sitemapFile, '</urlset>');

        $streamInfo = stream_get_meta_data($this->bodyFile);
        fclose($this->bodyFile);
        // removing temporary file
        unlink($streamInfo['uri']);

        if ($gzip) {
            $this->loc .= '.gz';
            $filenameGz = $filename . '.gz';
            fseek($sitemapFile, 0);
            $sitemapFileGz = gzopen($filenameGz, 'wb9');
            while (!feof($sitemapFile)) {
                gzwrite($sitemapFileGz, fread($sitemapFile, 65536));
            }
            gzclose($sitemapFileGz);
        }

        fclose($sitemapFile);
        if ($gzip) {
            unlink($filename);
        }
    }
359096
public FTPUploadRequest setUsernameAndPassword(String username, String password) {
        if (username == null || "".equals(username)) {
            throw new IllegalArgumentException("Specify FTP account username!");
        }

        if (password == null || "".equals(password)) {
            throw new IllegalArgumentException("Specify FTP account password!");
        }

        ftpParams.username = username;
        ftpParams.password = password;
        return this;
    }
68451
function ftpCwd(inPath, cb) {
    ftp.raw.cwd(inPath, function(err) {
      if (err) {
        ftp.raw.mkd(inPath, function(err) {
          if (err) {
            log.error('Error creating new remote folder ' + inPath + ' --> ' + err);
            cb(err);
          } else {
            log.ok('New remote folder created ' + inPath.yellow);
            ftpCwd(inPath, cb);
          }
        });
      } else {
        cb(null);
      }
    });
  }
966238
public function remoteUpload($url, $target)
	{
		$tmp_name = md5($url);
		$tmp_path = Storage::config('tmp_path').'/'.$tmp_name;
		
		if (!$this->remoteDownload($url, $tmp_path)) {
			return false;
		}
		
		return $this->upload($tmp_path, $target);
	}
858443
async function uploadFile(sftp, source, target) {
  return new Promise((resolve, reject) => {
    sftp.fastPut(source, target, error => (error ? reject(error) : resolve()));
  });
}
392665
static public void recursiveCreateDirectory(FTPClient ftpClient, String path) throws IOException {

		logger.info("Create Directory: {}", path);
		int createDirectoryStatus = ftpClient.mkd(path); // makeDirectory...
		logger.debug("Create Directory Status: {}", createDirectoryStatus);
		
		if (createDirectoryStatus == FTP_FILE_NOT_FOUND) {
			int sepIdx = path.lastIndexOf('/');
			if (sepIdx > -1) {
				String parentPath = path.substring(0, sepIdx);
				recursiveCreateDirectory(ftpClient, parentPath);

				logger.debug("2'nd CreateD irectory: {}", path);
				createDirectoryStatus = ftpClient.mkd(path); // makeDirectory...
				logger.debug("2'nd Create Directory Status: {}", createDirectoryStatus);
			}
		}
	}
857828
public function upload($destinationPath, $publicPath)
    {
        // Move takes the target directory and target filename as params
        $this->getFile()->move($destinationPath, $this->getFile()->getClientOriginalName());

        // Set the path property to the filename where you've saved the file
        $this->path = rtrim(str_ireplace($publicPath, '', $destinationPath), '/').'/'.$this->getFile()->getClientOriginalName();

        // Clean up the file property as you won't need it anymore
        $this->setFile(null);
    }
496287
@Override
  public FSDataOutputStream create(Path file, FsPermission permission,
      boolean overwrite, int bufferSize, short replication, long blockSize,
      Progressable progress) throws IOException {
    final FTPClient client = connect();
    Path workDir = new Path(client.printWorkingDirectory());
    Path absolute = makeAbsolute(workDir, file);
    if (exists(client, file)) {
      if (overwrite) {
        delete(client, file);
      } else {
        disconnect(client);
        throw new IOException("File already exists: " + file);
      }
    }
    Path parent = absolute.getParent();
    if (parent == null || !mkdirs(client, parent, FsPermission.getDefault())) {
      parent = (parent == null) ? new Path("/") : parent;
      disconnect(client);
      throw new IOException("create(): Mkdirs failed to create: " + parent);
    }
    client.allocate(bufferSize);
    // Change to parent directory on the server. Only then can we write to the
    // file on the server by opening up an OutputStream. As a side effect the
    // working directory on the server is changed to the parent directory of the
    // file. The FTP client connection is closed when close() is called on the
    // FSDataOutputStream.
    client.changeWorkingDirectory(parent.toUri().getPath());
    FSDataOutputStream fos = new FSDataOutputStream(client.storeFileStream(file
        .getName()), statistics) {
      @Override
      public void close() throws IOException {
        super.close();
        if (!client.isConnected()) {
          throw new FTPException("Client not connected");
        }
        boolean cmdCompleted = client.completePendingCommand();
        disconnect(client);
        if (!cmdCompleted) {
          throw new FTPException("Could not complete transfer, Reply Code - "
              + client.getReplyCode());
        }
      }
    };
    if (!FTPReply.isPositivePreliminary(client.getReplyCode())) {
      // The ftpClient is an inconsistent state. Must close the stream
      // which in turn will logout and disconnect from FTP server
      fos.close();
      throw new IOException("Unable to create file: " + file + ", Aborting");
    }
    return fos;
  }
118521
public static function getFileSizeFtp($path, $username = 'anonymous', $password = '')
    {
        try {
            $query = parse_url($path);
            $connection = ftp_connect($query['host'], isset($query['port']) ? $query['port'] : 21);
            ftp_login($connection, $username, $password);
            $file_size = ftp_size($connection, $query['path']);
            return $file_size ? $file_size : 0;
        } catch (\Exception $e) {
            return 0;
        }
    }
1150374
public static void updateFileFromUrl(final String sourceUrl, final String destinationFilePath,
                                         final String username, final String password,
                                         final URLFileUpdaterFactory factory) throws
        UpdateException {
        String tusername = username;
        String tpassword = password;
        URL url;
        try {
            url = new URL(sourceUrl);
            if (null == username && null == password && null != url.getUserInfo()) {
                //try to extract userinfo from URL
                final String userInfo = url.getUserInfo();
                final String[] split = userInfo.split(":", 2);
                if (2 == split.length) {
                    tusername = split[0];
                    tpassword = split[1];
                    url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile());
                }
            }
        } catch (MalformedURLException e) {
            throw new UpdateException(e);
        }
        final File destinationFile = new File(destinationFilePath);
        final long mtime = destinationFile.exists() ? destinationFile.lastModified() : 0;

        update(factory.fileUpdaterFromURL(url, tusername, tpassword), destinationFile);
        if (destinationFile.lastModified() > mtime) {
            logger.info("updated file: " + destinationFile.getAbsolutePath());
        } else {
            logger.info("file already up to date: " + destinationFile.getAbsolutePath());
        }

    }
374852
public static void initEndpointDirectory(MuleContext muleContext, String endpointName) throws Exception {

		logger.info("Init directory for endpoint: {}", endpointName);
		
		FTPClient ftpClient = null;

		try {
			ftpClient = getFtpClient(muleContext, endpointName);
	
			EndpointURI endpointURI = getImmutableEndpoint(muleContext, endpointName).getEndpointURI();
			String path = endpointURI.getPath();
	
			try {
				if (path.startsWith("/~/")) {
					path = path.substring(3); // Strip off the leading "/~/" to apply the command to the home-folder
				
				} else if (path.startsWith("/")) {
					path = path.substring(1); // Strip off the leading "/" to apply the command to the home-folder
				}
				recursiveDeleteDirectory(ftpClient, path);
				recursiveCreateDirectory(ftpClient, path);
			} catch (IOException e) {
				if (logger.isErrorEnabled()) logger.error("Failed to recursivly delete endpoint " + endpointName, e);
			}
			
		} finally {
			if (ftpClient != null) {
				ftpClient.disconnect();
			}
		}
	}