FTP-文件上传.

@param string $local_file 本地文件
@param string $ftp_file   Ftp文件

@return bool
974559
public function upload($local_file, $ftp_file)
    {
        if (empty($local_file) || empty($ftp_file)) {
            return false;
        }
        $ftppath = dirname($ftp_file);
        if (!empty($ftppath)) { //创建目录
            $this->make_dir($ftppath);
            @ftp_chdir($this->linkid, $ftppath);
            $ftp_file = basename($ftp_file);
        }
        $ret = ftp_nb_put($this->linkid, $ftp_file, $local_file, FTP_BINARY);
        while ($ret == FTP_MOREDATA) {
            $ret = ftp_nb_continue($this->linkid);
        }
        if ($ret != FTP_FINISHED) {
            return false;
        }

        return true;
    }
89671
private String[] matchLocalFiles(String local) throws SftpStatusException,
			SshException {

		// Resolve the search path as it may not be CWD
		String actualDir;
		String actualSearch;
		int fileSeparatorIndex;
		if ((fileSeparatorIndex = local.lastIndexOf(System
				.getProperty("file.separator"))) > -1
				|| (fileSeparatorIndex = local.lastIndexOf('/')) > -1) {
			actualDir = resolveLocalPath(local.substring(0, fileSeparatorIndex))
					.getAbsolutePath();
			actualSearch = (fileSeparatorIndex < local.length() - 1) ? local
					.substring(fileSeparatorIndex + 1) : "";
		} else {
			actualDir = lcwd;
			actualSearch = local;
		}

		File f;
		RegularExpressionMatching matcher;
		File[] files;
		switch (RegExpSyntax) {
		case GlobSyntax:
			f = new File(actualDir);
			matcher = new GlobRegExpMatching();
			files = listFiles(f);
			break;
		case Perl5Syntax:
			f = new File(actualDir);
			matcher = new Perl5RegExpMatching();
			files = listFiles(f);
			break;
		default:
			matcher = new NoRegExpMatching();
			files = new File[1];
			files[0] = new File(local);
		}

		return matcher.matchFileNamesWithPattern(files, actualSearch);
	}
1315812
public function put($localFile = null, $remoteFile = null, $mode = FTP_ASCII)
        {
            // attempt to upload file
            if(ftp_put(static::$_stream, $remoteFile, $localFile, $mode)) {
                // success
                return true;
            // upload failed
            } else {
                static::$error = "Failed to upload file \"{$localFile}\"";
                return false;
            }
        }
1245054
public function store($local, $remote = null)
	{
		// If remote file is not given, use the filename of the local file in the current
		// working directory.
		if ($remote == null)
		{
			$remote = basename($local);
		}

		// Determine file type
		$mode = $this->_findMode($remote);

		// If native FTP support is enabled let's use it...
		if (FTP_NATIVE)
		{
			// Turn passive mode on
			if (@ftp_pasv($this->conn, true) === false)
			{
				Log::add(__METHOD__ . ': Unable to use passive mode.', Log::WARNING, 'jerror');

				return false;
			}

			if (@ftp_put($this->conn, $remote, $local, $mode) === false)
			{
				Log::add(__METHOD__ . 'Bad response.', Log::WARNING, 'jerror');

				return false;
			}

			return true;
		}

		$this->_mode($mode);

		// Check to see if the local file exists and if so open it for reading
		if (@ file_exists($local))
		{
			$fp = fopen($local, "rb");

			if (!$fp)
			{
				Log::add(sprintf('%1$s: Unable to open local file for reading. Local path: %2$s', __METHOD__, $local), Log::WARNING, 'jerror');

				return false;
			}
		}
		else
		{
			Log::add(sprintf('%1$s: Unable to find local file. Local path: %2$s', __METHOD__, $local), Log::WARNING, 'jerror');

			return false;
		}

		// Start passive mode
		if (!$this->_passive())
		{
			@ fclose($fp);
			Log::add(__METHOD__ . ': Unable to use passive mode.', Log::WARNING, 'jerror');

			return false;
		}

		// Send store command to the FTP server
		if (!$this->_putCmd('STOR ' . $remote, array(150, 125)))
		{
			@ fclose($fp);
			@ fclose($this->dataconn);
			Log::add(
				sprintf('%1$s: Bad response.  Server response: %2$s [Expected: 150 or 125].  Path sent: %3$s', __METHOD__, $this->response, $remote),
				Log::WARNING, 'jerror'
			);

			return false;
		}

		// Do actual file transfer, read local file and write to data port connection
		while (!feof($fp))
		{
			$line = fread($fp, 4096);

			do
			{
				if (($result = @ fwrite($this->dataconn, $line)) === false)
				{
					Log::add(__METHOD__ . ': Unable to write to data port socket', Log::WARNING, 'jerror');

					return false;
				}

				$line = substr($line, $result);
			}

			while ($line != "");
		}

		fclose($fp);
		fclose($this->dataconn);

		if (!$this->_verifyResponse(226))
		{
			Log::add(
				sprintf('%1$s: Transfer failed.  Server response: %2$s [Expected: 226].  Path sent: %3$s', __METHOD__, $this->response, $remote),
				Log::WARNING, 'jerror'
			);

			return false;
		}

		return true;
	}
876814
public static function createFromLocalFile($file_name, $mime_type = null)
    {

        //Try to guess.  Might be questionable on non-*nix machines
        if ($mime_type === null) {
            $finfo = new \finfo(FILEINFO_MIME_TYPE);
            $info = $finfo->file($file_name);

            if ($info !== false) {
                $mime_type = $info;
            }
        }

        $content_length = filesize($file_name);
        $path_info = pathinfo($file_name);

        $instance = new self();
        $instance->fromStringArray([
            'MimeType' => $mime_type,
            'ContentLength' => $content_length,
            'FileName' => $path_info['basename'],
        ]);
        $instance->setLocalHandle(fopen($file_name, 'r'));

        return $instance;
    }
784540
public function get($remote_file, $local_file, $mode = null)
    {
        $mode = $mode ? $mode : FTP_ASCII;
        if (!@ftp_get($this->connection, $local_file, $remote_file, $mode)) {
            throw new \Exception("Could not get remote file:" . $remote_file);
        }

        return true;
    }
846609
public function upload($local_path, $remote_path, $mode = 'auto', $permissions = null)
	{
		if ( ! $this->_is_conn())
		{
			return false;
		}

		if ( ! is_file($local_path))
		{
			throw new \FtpFileAccessException('No source file');
			return false;
		}

		// Set the mode if not specified
		if ($mode == 'auto')
		{
			// Get the file extension so we can set the upload type
			$ext = pathinfo($local_path, PATHINFO_EXTENSION);
			$mode = $this->_settype($ext);
		}

		$mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY;

		$result = @ftp_put($this->_conn_id, $remote_path, $local_path, $mode);

		if ($result === false)
		{
			if ($this->_debug == true)
			{
				throw new \FtpFileAccessException('Unable to upload');
			}
			return false;
		}

		// Set file permissions if needed
		if ($permissions !== null)
		{
			$this->chmod($remote_path, (int) $permissions);
		}

		return true;
	}
902490
public function addFromString($localname, $contents)
    {
        if (false === $this->openned) {
            return false;
        }
        if (file_exists($this->filename) && !is_writable($this->filename)) {
            return false;
        }
        $localname = preg_replace("/(?:\.|\/)*(.*)/", "\\1", $localname);
        $localpath = dirname($localname);
        $tmpfilename = self::TMP_DIR . '/' . basename($localname);
        if (false !== file_put_contents($tmpfilename, $contents)) {
            $this->pclzip->delete(PCLZIP_OPT_BY_NAME, $localname);
            $add = $this->pclzip->add($tmpfilename, PCLZIP_OPT_REMOVE_PATH, self::TMP_DIR, PCLZIP_OPT_ADD_PATH, $localpath);
            unlink($tmpfilename);
            if (!empty($add)) {
                return true;
            }
        }
        return false;
    }
961803
def download_url(self, local_file):
        

        downloader = urllib.request.URLopener()
        downloader.retrieve(self.url, local_file)
285430
def get(self, remote_file, local_file):
        
        sftp = self.get_sftp()
        try:
            sftp.get(remote_file, local_file)
        except Exception as e:
            logger.error('下载文件失败')
            logger.error('remote: %s, local: %s' % (remote_file, local_file))
            logger.error(e)
405014
def _local_upload(self, filepath, remove=False):
        """"""
        if os.path.isfile(filepath):
            filename = os.path.basename(os.path.abspath(filepath))
            if filename and self.__isValidFilename(filename):
                suffix = self.__getFilenameSuffix(filename)
                try:
                    self.__unpack_tgz(os.path.abspath(filepath)) if self.__isValidTGZ(suffix) else self.__unpack_zip(os.path.abspath(filepath))
                finally:
                    if remove is True:
                        os.remove(filepath)
            else:
                raise InstallError("Invalid Filename")
        else:
            raise InstallError("Invalid Filepath")
726216
def copy_remote_directory_to_local(sftp, remote_path, local_path):
    ''''''
    try:
        os.makedirs(local_path, exist_ok=True)
        files = sftp.listdir(remote_path)
        for file in files:
            remote_full_path = os.path.join(remote_path, file)
            local_full_path = os.path.join(local_path, file)
            try:
                if sftp.listdir(remote_full_path):
                    copy_remote_directory_to_local(sftp, remote_full_path, local_full_path)
            except:
                sftp.get(remote_full_path, local_full_path)
    except Exception:
        pass
1139010
public static void downloadFile(String hostname, String username,
			String password, String remoteSource, String localDestination)
			throws Exception {
		FTPClient ftp = new FTPClient();
		ftp.connect(hostname);
		ftp.login(username, password);
		ftp.setFileType(FTP.BINARY_FILE_TYPE);
		ftp.enterLocalPassiveMode();
		FileOutputStream fos = new FileOutputStream(localDestination);
		ftp.retrieveFile(remoteSource, fos);
		ftp.logout();
		ftp.disconnect();
	}
1220939
public boolean upload(String path, String fileName, File file) {
		try (InputStream in = FileUtil.getInputStream(file)) {
			return upload(path, fileName, in);
		} catch (IOException e) {
			throw new FtpException(e);
		}
	}
1239120
public function is_uploaded_file( $file_url ) {

        // Set default return value.
        $is_uploaded_file = false;

        // Get WordPress upload directory information.
        $wp_upload_directory = wp_upload_dir();

        // Check if the WordPress upload directory url matches the file url.
        if ( false !== strpos( $file_url, $wp_upload_directory[ 'baseurl' ] ) ) {

            // We now know the file is one that was uploaded to WordPress.
            $is_uploaded_file = true;

        }

        return $is_uploaded_file;

    }
353323
public function chmod($permissions = 0, $remote_file = null)
    {
        if (\ftp_chmod($this->_stream, $permissions, $remote_file)) {
            return true;
        }

        $this->error = 'Failed to set file permissions for "'.$remote_file.'"';

        return false;
    }
1107326
public function uploadFile($localFile) {

        $sftp = $this->sftp;

        $localFile = realpath($localFile);

        $localData = file_get_contents($localFile);

        if ($localData === False) {
            throw new \RuntimeException("Could not read local file $localFile");
        }

        $remoteHome = ssh2_sftp_realpath($sftp, '.');

        if ($remoteHome === false) {
            throw new \RuntimeException("Could not establish remote home directory");
        }

        $remoteFile = "$remoteHome/".basename($localFile);
        $stream = fopen("ssh2.sftp://$sftp$remoteFile", 'w');

        if (!$stream) {
            throw new \RuntimeException("Could not open stream to $remoteFile");
        }

        if (fwrite($stream, $localData) === false) {
            throw new \RuntimeException("Could not write to remote file $remoteFile");
        }

        fclose($stream);

        return $remoteFile;
    }