/// <summary> /// Retrieves remote_file from the FTP server, and writes it to the given file pointer. /// </summary> /// <param name="ftp_stream">The link identifier of the FTP connection.</param> /// <param name="handle">An open file pointer in which we store the data.</param> /// <param name="remotefile">The remote file path.</param> /// <param name="mode">The transfer mode. Must be either FTP_ASCII or FTP_BINARY.</param> /// <param name="resumepos">The position in the remote file to start downloading from.</param> /// <returns>Returns TRUE on success or FALSE on failure.</returns> public static bool ftp_fget(PhpResource ftp_stream, PhpResource handle, string remotefile, int mode = FTP_IMAGE, int resumepos = 0) { // Check file resource var stream = PhpStream.GetValid(handle); if (stream == null) { return(false); } // Check ftp_stream resource var resource = ValidateFtpResource(ftp_stream); if (resource == null) { return(false); } resource.Client.DownloadDataType = (mode == FTP_ASCII) ? FtpDataType.ASCII : FtpDataType.Binary; // Ignore autoresume if autoseek is switched off if (resource.Autoseek && resumepos == FTP_AUTORESUME) { resumepos = 0; } if (resource.Autoseek && resumepos != 0) { if (resumepos == FTP_AUTORESUME) { stream.Seek(0, SeekOrigin.End); resumepos = stream.Tell(); } else { stream.Seek(resumepos, SeekOrigin.Begin); } } try { return(resource.Client.Download(stream.RawStream, remotefile, resumepos)); } catch (FtpException ex) { PhpException.Throw(PhpError.Warning, ex.InnerException.Message); } catch (ArgumentException ex) { PhpException.Throw(PhpError.Warning, Resources.Resources.file_not_exists, ex.ParamName); } return(false); }
public static PhpResource stream_filter_prepend(Context ctx, PhpResource stream, string filter, FilterChainOptions read_write = FilterChainOptions.ReadWrite, PhpValue parameters = default) { var s = PhpStream.GetValid(stream); if (s == null) return null; // false; var where = read_write & FilterChainOptions.ReadWrite; var added = PhpFilter.AddToStream(ctx, s, filter, where | FilterChainOptions.Head, parameters); // if (added.readFilter != null || added.writeFilter != null) { return new StreamFilterResource(s, added.writeFilter, added.readFilter); } else { return null; // false } }
/// <summary> /// Uploads the data from a file pointer to a remote file on the FTP server. /// </summary> /// <param name="ftp_stream">The link identifier of the FTP connection.</param> /// <param name="remote_file">The remote file path.</param> /// <param name="handle">An open file pointer on the local file. Reading stops at end of file.</param> /// <param name="mode">The transfer mode. Must be either FTP_ASCII or FTP_BINARY.</param> /// <param name="startpos">Not Supported</param> /// <returns>Returns TRUE on success or FALSE on failure.</returns> public static bool ftp_fput(PhpResource ftp_stream, string remote_file, PhpResource handle, int mode = FTP_IMAGE, int startpos = 0) { // Check file resource var stream = PhpStream.GetValid(handle); if (stream == null) { return(false); } // Check ftp_stream resource var resource = ValidateFtpResource(ftp_stream); if (resource == null) { return(false); } //stejny if (startpos != 0) { // There is no API for this parameter in FluentFTP Library. throw new NotImplementedException(); } resource.Client.UploadDataType = (mode == FTP_ASCII) ? FtpDataType.ASCII : FtpDataType.Binary; try { return(resource.Client.Upload(stream.RawStream, remote_file, FtpExists.Overwrite)); } catch (FtpException ex) { PhpException.Throw(PhpError.Warning, ex.InnerException.Message); } catch (ArgumentException ex) { PhpException.Throw(PhpError.Warning, Resources.Resources.file_not_exists, ex.ParamName); } return(false); }