By default, \phpseclib\Net\SFTP::put() does not read from the local filesystem. $data is dumped directly into $remote_file.
So, for example, if you set $data to 'filename.ext' and then do \phpseclib\Net\SFTP::get(), you will get a file, twelve bytes
long, containing 'filename.ext' as its contents.
Setting $mode to self::SOURCE_LOCAL_FILE will change the above behavior. With self::SOURCE_LOCAL_FILE, $remote_file will
contain as many bytes as filename.ext does on your local filesystem. If your filename.ext is 1MB then that is how
large $remote_file will be, as well.
Setting $mode to self::SOURCE_CALLBACK will use $data as callback function, which gets only one parameter -- number of bytes to return, and returns a string if there is some data or null if there is no more data
If $data is a resource then it'll be used as a resource instead.
Currently, only binary mode is supported. As such, if the line endings need to be adjusted, you will need to take
care of that, yourself.
$mode can take an additional two parameters - self::RESUME and self::RESUME_START. These are bitwise AND'd with
$mode. So if you want to resume upload of a 300mb file on the local file system you'd set $mode to the following:
self::SOURCE_LOCAL_FILE | self::RESUME
If you wanted to simply append the full contents of a local file to the full contents of a remote file you'd replace
self::RESUME with self::RESUME_START.
If $mode & (self::RESUME | self::RESUME_START) then self::RESUME_START will be assumed.
$start and $local_start give you more fine grained control over this process and take precident over self::RESUME
when they're non-negative. ie. $start could let you write at the end of a file (like self::RESUME) or in the middle
of one. $local_start could let you start your reading from the end of a file (like self::RESUME_START) or in the
middle of one.
Setting $local_start to > 0 or $mode | self::RESUME_START doesn't do anything unless $mode | self::SOURCE_LOCAL_FILE.
public put ( string $remote_file, string | resource $data, integer $mode = self::SOURCE_STRING, integer $start, integer $local_start, callable | null $progressCallback = null ) : boolean | ||
$remote_file | string | |
$data | string | resource | |
$mode | integer | |
$start | integer | |
$local_start | integer | |
$progressCallback | callable | null | |
return | boolean |