Hướng dẫn php download file from ftp server - tệp tải xuống php từ máy chủ ftp

Tôi đang sử dụng định dạng sau trong mã PHP để tải xuống các tệp từ máy chủ FTP.

file_put_contents(
            $filePath.$fileName, file_get_contents(
                ftp://username:password@server_name/folder_name/xyz#123.csv.zip
            )
);    

Tôi đang gặp lỗi 550 vì tên tệp chứa '#'. Làm thế nào để tránh lỗi. Ngoài ra lớp PHP tốt nhất để thực hiện các hoạt động khác nhau trên FTP là gì?

hỏi ngày 17 tháng 10 năm 2011 lúc 11:36Oct 17, 2011 at 11:36

Hướng dẫn php download file from ftp server - tệp tải xuống php từ máy chủ ftp

4

Dùng cái này

<?php

// define some variables
$local_file = 'filename.jpg';
$server_file = 'filename.jpg';
$ftp_server="www.abc.com";
$ftp_user_name="username";
$ftp_user_pass="password";

$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successfully written to $local_file\n";
}
else {
    echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);

?>

Đã trả lời ngày 12 tháng 2 năm 2012 lúc 10:30Feb 12, 2012 at 10:30

user580950user580950user580950

3,45912 Huy hiệu vàng46 Huy hiệu bạc91 Huy hiệu Đồng12 gold badges46 silver badges91 bronze badges

4

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;

Đã trả lời ngày 3 tháng 10 năm 2013 lúc 16:21Oct 3, 2013 at 16:21

Quản trị viênadmin

1672 Huy hiệu bạc5 Huy hiệu Đồng2 silver badges5 bronze badges

Try:

$output = exec("wget -N ftp:///path/to directory/file 2>&1 |grep 'filename w/o extension'|grep -v ftp|grep -v =");
print $output <to check if file downloaded or not>

Đã trả lời ngày 2 tháng 8 năm 2013 lúc 15:20Aug 2, 2013 at 15:20

1

10 năm trước

Apurvavora19 tại gmail dot com ¶Downloads a file from the FTP server

Scott Dot Chu tại Udngroup Dot Com ¶

6 năm trước(
    FTP\Connection $ftp,
    string $local_filename,
    string $remote_filename,
    int $mode = FTP_BINARY,
    int $offset = 0
): bool

w dot danford tại điện tử-software dot com ¶

Danny tại Ingeniarte dot com ¶

11 năm trướcFTP\Connection instance.

Làm thế nào để tải xuống tệp từ FTP trong PHP?

Hàm ftp_get () được sử dụng để tải xuống một tệp từ máy chủ FTP. Hàm ftp_get () lấy một tệp từ xa từ máy chủ FTP và lưu nó vào một tệp cục bộ. Chức năng này đã được giới thiệu trong PHP 4.

Làm cách nào để tải xuống các tệp từ máy chủ FTP?

Tải lên và tải xuống một tệp lên/từ máy chủ FTP.

Điều hướng đến thư mục từ xa nơi tệp bạn muốn tải xuống,.

Điều hướng đến thư mục cục bộ nơi bạn muốn lưu trữ tệp đã tải xuống,.

<?php

// define some variables
$local_file = 'filename.jpg';
$server_file = 'filename.jpg';
$ftp_server="www.abc.com";
$ftp_user_name="username";
$ftp_user_pass="password";

$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successfully written to $local_file\n";
}
else {
    echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);

?>
4 or FTP_BINARY.

Chọn tệp bạn muốn tải xuống từ thư mục từ xa và ..

Nhấp vào nút tải xuống ..

Làm cách nào để tải xuống một tệp từ dòng lệnh FTP?

Cho tiện ích dòng lệnh FTP.

<?php

// define some variables
$local_file = 'filename.jpg';
$server_file = 'filename.jpg';
$ftp_server="www.abc.com";
$ftp_user_name="username";
$ftp_user_pass="password";

$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successfully written to $local_file\n";
}
else {
    echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);

?>
7 on success or
<?php

// define some variables
$local_file = 'filename.jpg';
$server_file = 'filename.jpg';
$ftp_server="www.abc.com";
$ftp_user_name="username";
$ftp_user_pass="password";

$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successfully written to $local_file\n";
}
else {
    echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);

?>
8
on failure.

Nhập một trong các lệnh FTP sau đây để liệt kê các tệp trong thư mục phụ chính sách: Dir. ls ..

Nhập lệnh FTP sau để bắt đầu tải xuống tệp: Nhận tên tệp. Tệp đã tải xuống được đặt trong thư mục hiện tại trong đó chương trình FTP được khởi chạy trên hệ thống của bạn ..Scott Dot Chu tại Udngroup Dot Com ¶
8.1.0 6 năm trướcFTP\Connection instance now; previously, a resource was expected.
7.3.0 w dot danford tại điện tử-software dot com ¶

Danny tại Ingeniarte dot com ¶

11 năm trướcftp_get() example

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
1

Làm thế nào để tải xuống tệp từ FTP trong PHP?

  • Hàm ftp_get () được sử dụng để tải xuống một tệp từ máy chủ FTP. Hàm ftp_get () lấy một tệp từ xa từ máy chủ FTP và lưu nó vào một tệp cục bộ. Chức năng này đã được giới thiệu trong PHP 4.
  • ftp_fget () - Tải xuống tệp từ máy chủ FTP và lưu vào tệp mở
  • ftp_nb_get () - Lấy một tệp từ máy chủ FTP và ghi nó vào tệp cục bộ (không chặn)
  • ftp_nb_fget () - Lấy một tệp từ máy chủ FTP và ghi nó vào một tệp mở (không chặn)

Cudi ¶

13 năm trước

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
2

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
3

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
4

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
5

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
6

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
7

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
8

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
9

Bob tại Notallhere dot com ¶

9 năm trước

$output = exec("wget -N ftp:///path/to directory/file 2>&1 |grep 'filename w/o extension'|grep -v ftp|grep -v =");
print $output <to check if file downloaded or not>
0

$output = exec("wget -N ftp:///path/to directory/file 2>&1 |grep 'filename w/o extension'|grep -v ftp|grep -v =");
print $output <to check if file downloaded or not>
1

$output = exec("wget -N ftp:///path/to directory/file 2>&1 |grep 'filename w/o extension'|grep -v ftp|grep -v =");
print $output <to check if file downloaded or not>
2

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
9

Ramiro tại Qusarcr dot com

19 năm trước

$output = exec("wget -N ftp:///path/to directory/file 2>&1 |grep 'filename w/o extension'|grep -v ftp|grep -v =");
print $output <to check if file downloaded or not>
4

anomie tại người dùng dot sf dot net ¶

15 năm trước

$output = exec("wget -N ftp:///path/to directory/file 2>&1 |grep 'filename w/o extension'|grep -v ftp|grep -v =");
print $output <to check if file downloaded or not>
5

Nate từ Ruggf Family.com

14 năm trước

$output = exec("wget -N ftp:///path/to directory/file 2>&1 |grep 'filename w/o extension'|grep -v ftp|grep -v =");
print $output <to check if file downloaded or not>
6

$output = exec("wget -N ftp:///path/to directory/file 2>&1 |grep 'filename w/o extension'|grep -v ftp|grep -v =");
print $output <to check if file downloaded or not>
7

$output = exec("wget -N ftp:///path/to directory/file 2>&1 |grep 'filename w/o extension'|grep -v ftp|grep -v =");
print $output <to check if file downloaded or not>
8

$output = exec("wget -N ftp:///path/to directory/file 2>&1 |grep 'filename w/o extension'|grep -v ftp|grep -v =");
print $output <to check if file downloaded or not>
9

mroerick tại gmx dot net ¶

13 năm trước

$ftp0

$ftp1

$ftp2

$ftp3

Aditya P dot Bhatt (Adityabhai tại Gmail Dot Com) ¶

14 năm trước

$ftp4

$ftp5

$ftp6

mpatnode tại yahoo dot com ¶

4 năm trước

$ftp7

Miki tại epoch dot co dot il ¶

9 năm trước

$ftp8

$ftp9

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
9

anomie tại người dùng dot sf dot net ¶

15 năm trước

$local_filename1

Quản trị viên tại Gesoft Dot org ¶

16 năm trước

$local_filename2

$local_filename3

$local_filename4

$local_filename5

$local_filename6

$local_filename7

$local_filename8

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
9

Corey-Holzer tại NYC Dot Rr dot com

18 năm trước

$remote_filename0

thivierr tại telus dot net ¶

18 năm trước

$remote_filename1

$remote_filename2

$remote_filename3

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
9

thivierr tại telus dot net ¶

Giáo xứ Ben ¶

$remote_filename5

$remote_filename6

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
9

10 năm trước

4 năm trước

$remote_filename8

$remote_filename9

$mode0

$mode1

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
9

Miki tại epoch dot co dot il ¶

9 năm trước

$mode3

$mode4

$mode5

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
9

anomie tại người dùng dot sf dot net ¶

15 năm trước

$mode7

Quản trị viên tại Gesoft Dot org ¶

16 năm trước

$mode8

$mode9

true == (
$data = @
    file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
    )
        ?
    file_put_contents('xyz#123.csv', $data)
        :
    exit;
9

Làm thế nào để tải xuống tệp từ FTP trong PHP?

Hàm ftp_get () được sử dụng để tải xuống một tệp từ máy chủ FTP. Hàm ftp_get () lấy một tệp từ xa từ máy chủ FTP và lưu nó vào một tệp cục bộ. Chức năng này đã được giới thiệu trong PHP 4. is used to download a file from the FTP server. The ftp_get() function retrieves a remote file from the FTP server, and saves it into a local file. This function was introduced in PHP 4.

Làm cách nào để tải xuống các tệp từ máy chủ FTP?

Tải lên và tải xuống một tệp lên/từ máy chủ FTP..
Điều hướng đến thư mục từ xa nơi tệp bạn muốn tải xuống,.
Điều hướng đến thư mục cục bộ nơi bạn muốn lưu trữ tệp đã tải xuống,.
Chọn tệp bạn muốn tải xuống từ thư mục từ xa và ..
Nhấp vào nút tải xuống ..

Làm cách nào để tải xuống một tệp từ dòng lệnh FTP?

Cho tiện ích dòng lệnh FTP..
Nhập một trong các lệnh FTP sau đây để liệt kê các tệp trong thư mục phụ chính sách: Dir.ls ..
Nhập lệnh FTP sau để bắt đầu tải xuống tệp: Nhận tên tệp.Tệp đã tải xuống được đặt trong thư mục hiện tại trong đó chương trình FTP được khởi chạy trên hệ thống của bạn ..

Làm cách nào để tải xuống tệp từ PHP?

PHP cho phép bạn tải xuống tệp dễ dàng bằng hàm readfile () tích hợp.Hàm readfile () đọc một tệp và ghi nó vào bộ đệm đầu ra ...
Làm cách nào để tải xuống các tệp từ máy chủ FTP?
Tiêu đề ('Loại nội dung: Ứng dụng/Dòng octet') ;.
Tiêu đề ("Mã hóa chuyển đổi nội dung: UTF-8") ;.