Class: SFML::Ftp
- Inherits:
-
Object
- Object
- SFML::Ftp
- Defined in:
- ext/network/ftp.c,
ext/network/ftp.c
Overview
A basic FTP client. Every command method blocks until the server replies and returns an FtpResponse (or a more specific subtype).
Instance Method Summary collapse
-
#change_directory(directory) ⇒ FtpResponse
Changes the current working directory on the server.
-
#connect(address, port = 21, timeout = Time.zero) ⇒ FtpResponse
Connects to the specified FTP server.
-
#create_directory(name) ⇒ FtpResponse
Creates a directory named
nameon the server. -
#delete_directory(name) ⇒ FtpResponse
Deletes the directory named
nameon the server. -
#delete_file(name) ⇒ FtpResponse
Deletes the file named
nameon the server. -
#directory_listing(directory = nil) ⇒ FtpListingResponse
Lists the contents of
directory(or the current working directory if omitted/nil). -
#disconnect ⇒ FtpResponse
Closes the connection with the server.
-
#download(remote_file, local_path, mode = :binary) ⇒ FtpResponse
Downloads
remote_filefrom the server intolocal_path(a local directory). -
#new ⇒ Ftp
constructor
Creates a new FTP client.
-
#keep_alive ⇒ FtpResponse
Sends a null command to keep the connection alive.
-
#login(name, password) ⇒ FtpResponse
Logs in with the given
nameandpassword. -
#login_anonymous ⇒ FtpResponse
Logs in using the standard "anonymous" account.
-
#parent_directory ⇒ FtpResponse
Moves to the parent directory of the current working directory.
-
#rename_file(file, new_name) ⇒ FtpResponse
Renames
filetonew_nameon the server. -
#send_command(command, parameter = nil) ⇒ FtpResponse
Sends a raw FTP command, for functionality not exposed by the other methods.
-
#upload(local_file, remote_path, mode = :binary, append = false) ⇒ FtpResponse
Uploads
local_filetoremote_path(a directory on the server). -
#working_directory ⇒ FtpDirectoryResponse
Returns the current working directory on the server.
Constructor Details
#new ⇒ Ftp
Creates a new FTP client.
163 164 165 |
# File 'ext/network/ftp.c', line 163 static VALUE Ftp_initialize(VALUE self) { return self; } |
Instance Method Details
#change_directory(directory) ⇒ FtpResponse
Changes the current working directory on the server.
274 275 276 277 |
# File 'ext/network/ftp.c', line 274
static VALUE Ftp_change_directory(VALUE self, VALUE rb_directory) {
return FtpResponse_wrap(
sfFtp_changeDirectory(Get_Ftp_Struct(self), StringValueCStr(rb_directory)));
}
|
#connect(address, port = 21, timeout = Time.zero) ⇒ FtpResponse
Connects to the specified FTP server. Blocks until connected or
timeout elapses.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'ext/network/ftp.c', line 175
static VALUE Ftp_connect(int argc, VALUE* argv, VALUE self) {
VALUE rb_address, rb_port, rb_timeout;
sfTime timeout = sfTime_Zero;
unsigned short port = 21;
rb_scan_args(argc, argv, "12", &rb_address, &rb_port, &rb_timeout);
if (!NIL_P(rb_port)) {
port = (unsigned short)NUM2INT(rb_port);
}
if (!NIL_P(rb_timeout)) {
timeout = time_from_rb(rb_timeout);
}
return FtpResponse_wrap(sfFtp_connect(
Get_Ftp_Struct(self), ip_address_from_rb(rb_address, sfIpAddress_None), port, timeout));
}
|
#create_directory(name) ⇒ FtpResponse
Creates a directory named name on the server.
297 298 299 |
# File 'ext/network/ftp.c', line 297
static VALUE Ftp_create_directory(VALUE self, VALUE rb_name) {
return FtpResponse_wrap(sfFtp_createDirectory(Get_Ftp_Struct(self), StringValueCStr(rb_name)));
}
|
#delete_directory(name) ⇒ FtpResponse
Deletes the directory named name on the server.
308 309 310 |
# File 'ext/network/ftp.c', line 308
static VALUE Ftp_delete_directory(VALUE self, VALUE rb_name) {
return FtpResponse_wrap(sfFtp_deleteDirectory(Get_Ftp_Struct(self), StringValueCStr(rb_name)));
}
|
#delete_file(name) ⇒ FtpResponse
Deletes the file named name on the server.
331 332 333 |
# File 'ext/network/ftp.c', line 331
static VALUE Ftp_delete_file(VALUE self, VALUE rb_name) {
return FtpResponse_wrap(sfFtp_deleteFile(Get_Ftp_Struct(self), StringValueCStr(rb_name)));
}
|
#directory_listing(directory = nil) ⇒ FtpListingResponse
Lists the contents of directory (or the current working directory if
omitted/nil).
258 259 260 261 262 263 264 265 |
# File 'ext/network/ftp.c', line 258
static VALUE Ftp_directory_listing(int argc, VALUE* argv, VALUE self) {
VALUE rb_directory;
rb_scan_args(argc, argv, "01", &rb_directory);
return FtpListingResponse_wrap(sfFtp_getDirectoryListing(
Get_Ftp_Struct(self), NIL_P(rb_directory) ? NULL : StringValueCStr(rb_directory)));
}
|
#disconnect ⇒ FtpResponse
Closes the connection with the server.
224 225 226 |
# File 'ext/network/ftp.c', line 224 static VALUE Ftp_disconnect(VALUE self) { return FtpResponse_wrap(sfFtp_disconnect(Get_Ftp_Struct(self))); } |
#download(remote_file, local_path, mode = :binary) ⇒ FtpResponse
Downloads remote_file from the server into local_path (a local
directory). mode is an FtpTransferMode name or value.
343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'ext/network/ftp.c', line 343
static VALUE Ftp_download(int argc, VALUE* argv, VALUE self) {
VALUE rb_remote, rb_local, rb_mode;
sfFtpTransferMode mode = sfFtpBinary;
rb_scan_args(argc, argv, "21", &rb_remote, &rb_local, &rb_mode);
if (!NIL_P(rb_mode)) {
mode = ftp_transfer_mode_from_rb(rb_mode);
}
return FtpResponse_wrap(sfFtp_download(Get_Ftp_Struct(self), StringValueCStr(rb_remote),
StringValueCStr(rb_local), mode));
}
|
#keep_alive ⇒ FtpResponse
Sends a null command to keep the connection alive.
235 236 237 |
# File 'ext/network/ftp.c', line 235 static VALUE Ftp_keep_alive(VALUE self) { return FtpResponse_wrap(sfFtp_keepAlive(Get_Ftp_Struct(self))); } |
#login(name, password) ⇒ FtpResponse
Logs in with the given name and password.
212 213 214 215 |
# File 'ext/network/ftp.c', line 212
static VALUE Ftp_login(VALUE self, VALUE rb_name, VALUE rb_password) {
return FtpResponse_wrap(
sfFtp_login(Get_Ftp_Struct(self), StringValueCStr(rb_name), StringValueCStr(rb_password)));
}
|
#login_anonymous ⇒ FtpResponse
Logs in using the standard "anonymous" account.
201 202 203 |
# File 'ext/network/ftp.c', line 201 static VALUE Ftp_login_anonymous(VALUE self) { return FtpResponse_wrap(sfFtp_loginAnonymous(Get_Ftp_Struct(self))); } |
#parent_directory ⇒ FtpResponse
Moves to the parent directory of the current working directory.
286 287 288 |
# File 'ext/network/ftp.c', line 286 static VALUE Ftp_parent_directory(VALUE self) { return FtpResponse_wrap(sfFtp_parentDirectory(Get_Ftp_Struct(self))); } |
#rename_file(file, new_name) ⇒ FtpResponse
Renames file to new_name on the server.
319 320 321 322 |
# File 'ext/network/ftp.c', line 319
static VALUE Ftp_rename_file(VALUE self, VALUE rb_file, VALUE rb_new_name) {
return FtpResponse_wrap(sfFtp_renameFile(Get_Ftp_Struct(self), StringValueCStr(rb_file),
StringValueCStr(rb_new_name)));
}
|
#send_command(command, parameter = nil) ⇒ FtpResponse
Sends a raw FTP command, for functionality not exposed by the other
methods. command should not include the trailing CRLF.
394 395 396 397 398 399 400 401 402 |
# File 'ext/network/ftp.c', line 394
static VALUE Ftp_send_command(int argc, VALUE* argv, VALUE self) {
VALUE rb_command, rb_parameter;
rb_scan_args(argc, argv, "11", &rb_command, &rb_parameter);
return FtpResponse_wrap(
sfFtp_sendCommand(Get_Ftp_Struct(self), StringValueCStr(rb_command),
NIL_P(rb_parameter) ? NULL : StringValueCStr(rb_parameter)));
}
|
#upload(local_file, remote_path, mode = :binary, append = false) ⇒ FtpResponse
Uploads local_file to remote_path (a directory on the server).
mode is an FtpTransferMode name or value; if append is true, the
data is appended to an existing remote file of the same name instead of
overwriting it.
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'ext/network/ftp.c', line 367
static VALUE Ftp_upload(int argc, VALUE* argv, VALUE self) {
VALUE rb_local, rb_remote, rb_mode, rb_append;
sfFtpTransferMode mode = sfFtpBinary;
bool append = false;
rb_scan_args(argc, argv, "22", &rb_local, &rb_remote, &rb_mode, &rb_append);
if (!NIL_P(rb_mode)) {
mode = ftp_transfer_mode_from_rb(rb_mode);
}
if (!NIL_P(rb_append)) {
append = RTEST(rb_append);
}
return FtpResponse_wrap(sfFtp_upload(Get_Ftp_Struct(self), StringValueCStr(rb_local),
StringValueCStr(rb_remote), mode, append));
}
|
#working_directory ⇒ FtpDirectoryResponse
Returns the current working directory on the server.
246 247 248 |
# File 'ext/network/ftp.c', line 246 static VALUE Ftp_working_directory(VALUE self) { return FtpDirectoryResponse_wrap(sfFtp_getWorkingDirectory(Get_Ftp_Struct(self))); } |