/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] FTP in PHP

I have been playing with a PHP page I am writing to connect to my FTP server on the local drive and I am encountering problems.

What I am trying to do is to get an FTP page setup so that I can press a button and the page will then: –

Connect to FTP server
Login with user name and password
Turn on Passive mode
Change to the htdocs folder
upload a file called data.txt to the current working directory.
upload a file called go.php to current working directory
verify the file is in place (not yet implemented)
close the connection
then output a URL to the file called go.php, eg [url]http://localhost/go.php?src=data.txt[/url]

go.php processes the file and then deletes it as well as the file called go.php

Now this is the issue…

In the FTP server I can see the connection open up, the login process OK and then turns on passive mode, gets the CWD, changes to the htdocs folder, attempts to upload the data.txt file but then returns an error saying that the file name is invalid despite being valid! and I can see the full path to the file!

I have looked at many examples of using the basic PHP ftp functions which is what I need to use and all the demonstrations show the same method of working.

basically they layout is something like

[code=php] $con = ftp_connect(“localhost”); // ftp_server
// login with username and password
$log = ftp_login($con, “test”, “password”);

if($log){ // we are logged in.
$cwd = ftp_pwd($con); // the current working directory
// turn passive mode on
ftp_pasv($con, true);
// upload a file
ftp_chdir($con, “htdocs”); // change to that directory
ftp_put($con, “data.txt”, “data.txt”, FTP_ASCII);
ftp_put($con, “go.php”, “go.php”, FTP_ASCII);
// close the connection
ftp_close($con);
}
echo ($log?”Done.”:”Error!”); [/code]

and this working but not uploading.

What am I missing or doing wrong?

Any help is appreciated.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@rootauthorJun 28.2008 — Success!

[SIZE="1"][FONT="Lucida Console"]04:24:04.669 [2044] Client connected from 127.0.0.1.

04:24:04.679 [2044] 220 This is ****** local server administration.

04:24:04.679 [2044] USER *
**
*******

04:24:04.679 [2044] 331 Password required for *
**
*******

04:24:04.679 [2044] PASS *
**
*******

04:24:04.679 [2044] 230 User successfully logged in.

04:24:04.679 [2044] PASV

04:24:04.689 [2044] 227 Entering Passive Mode (127,0,0,1,4,0).

04:24:04.699 [2044] PWD

04:24:04.699 [2044] 257 "/" is current directory.

04:24:04.699 [2044] CWD htdocs

04:24:04.709 [2044] 250 "/htdocs" is current directory.

04:24:04.709 [2044] PWD

04:24:04.709 [2044] 257 "/htdocs" is current directory.

04:24:04.759 [2044] STOR data.txt

04:24:04.769 [2044] 150 Opening BINARY mode data connection for file transfer.

04:24:05.190 [2044] 226 Transfer complete

04:24:05.270 [2044] PASV

04:24:05.300 [2044] 227 Entering Passive Mode (127,0,0,1,4,0).

04:24:05.360 [2044] STOR go.php

04:24:05.380 [2044] 150 Opening BINARY mode data connection for file transfer.

04:24:05.480 [2044] 226 Transfer complete

04:24:05.500 [2044] Client disconnected from 127.0.0.1.

[/FONT][/SIZE]
[/quote]


I now know it is possible for me to interact with the local server, this is the largest issue over with.
×

Success!

Help @root spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...