Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP stupid question

Status
Not open for further replies.

daybase

Technical User
Joined
Dec 13, 2002
Messages
115
Location
GB
I'm on hour one of looking at using ftp functions instead of uploads and have numerous stupid questions but here's one that gors straight to the core.

Using examples from the PHP manual I am connecting fine, even changing directories but the upload just won't. I am defining variables:

<?php
$ftp_server="$ftp_user_name="mylogin";
$ftp_user_pass="mypass";
$destination_file="uploadfile.txt";
$source_file="a:\uploadfile.txt";
etc etc

then onto the important bit

$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

I know I'm doing (or not doing) something very obvious and/or silly so be gentle with me - HELP!
 
Do you have the source file on a floppy? also have you included the actual connect statement ie:
$ftpserver = "ftp/$conn_id = ftp_connect($ftp_server);

and then close the connection

ftp_close($conn_id) ??
 
Yes to all that - playing with other functions such as FTP_MKDIR and all such things seem to wotk ok - creating directories in the right place and stuff.

Am I right to just specifiy a file by payh/file name - I don't need to select a file from a form or anything as with upload?

You might regret helping me... do appreciate it though
 
try using the ftp_put command on its own ie
ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
without the variable. it does not seem to require it
 
No - that didn't help - the variable is only there to test for successful upload anyway. I really am baffled as all other commands work perfectly. I can create and move around directories beautifully but can't upload anything to them.
 
See - simple answer to a stupid question!!

Many thanks
 
Nope! Didn't work in fact it seems a backward step - won't connect with ftp:// etc

Connects fine with just I can make and change directories which tells me the connection is genuine (I think) but the upload bit won't.
 
ok, next question, are you actually running an ftp server on your machine?
 
Yes - on the server - I am successfully uploading files (non-ftp) and like I say all the other stuff works - making & changing directories and stuff just the upload that won't.
 
Can you FTP to the server using the command line rather than PHP ?.
 
Forgive my stupidity but not sure what you mean. I have no problem with FTP to the site in any other method I have tried. Both traditional FTP clients and simply using the browser. Does that help any?

My background is "try it and see what happens then learn from it" so I do struggle with tech terms.

I am puzzled by the failure to connect when the server is specified as ftp:// when it will connect happily as And as you will read it is the fact that using PHP FTP functions I can make and change directories all day long but can't upload.

Frustration!!
 
You answered my question. As long as you can use the ftp client from the machine you run php,using the same username and password on and sucessfully do a transfer it shows that the ftp 'environment' is ok.
What I'd like to see is a snipet of the code and the error it produces.
Can you do a get from the server in PHP?, are you looking in the correct place on the ftp server machine ?
Finally have you tried running the PHP code from the command line ?.
 
Full Code:

<?php
$ftp_server="$ftp_user_name="daybase";
$ftp_user_pass="mypassword";
$destination_file="test.txt";
$source_file="d:\dja\test.txt";

// set up basic connection
$conn_id = ftp_connect($ftp_server);

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

// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name<p>";

//stuff to test connection
ftp_chdir($conn_id, "/djapix/");
echo ftp_pwd($conn_id);
echo"<p>";
ftp_mkdir($conn_id, "testdir");
//just testing!
}

// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_ASCII);

// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}

// close the FTP stream
ftp_close($conn_id);
?>



Output:

Connected to for user daybase
/djapix

FTP upload has failed!


And in the /djapix directory I now have a lovely subdirectory called testdir

So something is working ok.

Not tried get yet but will. Really do appreciate any help - hope you like a challenge
 
Love a challenge !, have a look in the /djapix directory is the file in there ?, you will have to change dir into testdir to put the file in there.
One thing is interesring. In the old days you had to set up a vurtual directory kind of thing for FTP to work e.g. you would have a real directory of /usr/fred and create the virtual directory billy to point to /usr/fred. You would ftp to /billy which would really use /usr/fred.
Antother final thought do you have permissions to create files.
The really odd thing is yiou can use the command line to do this, FTP is a client server protocl the actual stuff happends on the FTP server machine so shouldn't care where it comes from.
 
Nope - it isn't in the djapix directory either. In fact unless it is hiding somewhere really strange it isn't on the server at all. My feeling is that it's not the FTP as such at fault but locating the file to upload - what do you think?
 
I think your right here's some rambling.

If you fire up ftp on the machine that PHP runns on, from the same account and do the the same steps the script does, same user name , password etc and put the file, you should see it if you do an ls -l at the ftp prompt. If this works the file has got to the other side. You now need to confirm that you are looking in the correct place (from the shell or command prompt) by finding out of you are pointing at a virtual directory or not. With my isp FTP shows the directory as / but from linux it's actually /home/data
Do you own the FTP server machine or is it an ISP owned thing.
You could try a put with a bizare filname like phpiscool.txt and issue a find comnnd on linux or search on windows and see if it's lurking any where.
Can you try a print_r on the response from ftp_put, the book says true or false but I wonder if it does return a response code.
I'll try with your code when I get home. I'm in the UK (I'm assuming you are from the domain) so we are in the same time zone and see what I get.
I think you FTP is ok it it just finding out where it is, anyhow it all makes for good fun running up to easter !
 
will take me a bit to study that and act accordingly but in answer to your question about the server - it is a managed (windows) server provided by oneandone.co.uk

Oh and yes - UK it is - Manchester to be precise.

Thanks again for your interest and your help (and your patience)
 
I'm quite near you ! (just outside Rochdale)
Have you got the original details from oneandone ?, I just looked at the site and I can't find much detail. They will have given you a list of settings and configs one of which, I'll wager, is the directory structure they set up for you.
 
Ok,

I got it to work on my (linux) server after a bit of fiddleing.

The $sourcefile value in the source file (d:\dja\test.txt) is this on your Pc or on the remote server ?. If it on your PC the PHP script won't see it as it runs on the remote server, which should show the probem (not fix it).
I suspect it is on your PC as if it was on the remote machine you could just copy it around rather than FTP it.
Hope this is it !!, also I've found some tine on wondoows use the UNIx slash as the windows slaos will translee the zd into something and the \t into a tab.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top