$local = 'WP_Inv.csv';
$remote = 'WP_Inv.csv';
$user = "User861";
$pass = "topsecret";
$host = 'ftp.server.com';
$port = '21';
$timeout = '90';
$type = FTP_ASCII;
$conn_id = ftp_connect($host,$port,$timeout);
$login = ftp_login($conn_id, $user, $pass);
ftp_put($conn_id, $remote, $local, $type);
returning the following error when ran from shell:
The very last line is showing an error, any help would be great I am pulling my hair out!
PHP Warning: ftp_put(): Server cannot accept argument.
(Yes I close my connection later in the code)
Have you tried turning on passive mode? I've had the same issue in the past and its because the machine running the php code and the ftp server could not handshake on an active connection.
http://php.net/manual/en/function.ftp-pasv.php
bool ftp_pasv ( resource $ftp_stream , bool $pasv )
ftp_pasv() turns on or off passive mode. In passive mode, data connections are initiated by the client, rather than by the server. It may be needed if the client is behind firewall.
Please note that ftp_pasv() can only be called after a successfull login or otherwise it will fail.
Related
According to RFC 2228 the AUTH is an FTP command which can be used with one of an authentication mechanism (TLS or SSL), in order to secure both data channel and control channel.
I'm wondering if I can use this command with a non-secure connection (regular FTP) with ftp_connect function, like this :
$conn = ftp_connect('hostname');
if (is_ressoure($conn)) {
$command = ftp_raw($conn, 'AUTH TLS');
$responseCode = (int) substr($command[0], 0, 3);
if ($responseCode === 234) {
// AUTH TLS success
login(); // secured
} else { // if TLS rejected try SSL
$command = ftp_raw($conn, 'AUTH SSL');
$responseCode = (int) substr($command[0], 0, 3);
if ($responseCode === 234) {
// SSL authentication success
login(); // secured
} else {
// Cannot secure the data channel and command channel
die();
}
}
}
I know that the AUTH command used with an explicit FTP/SSL connection with ftp_ssl_connect, I'm confused and I want to know if this command is useless with a regular FTP connection?
Thanks in advance!
AUTH TLS/SSL turns the connection into encrypted. If you use it with a plain ftp_connect connection, the connection will stop working. The server will expect encrypted commands (and will send encrypted responses) and the client (PHP FTP module) will keep sending unencrypted commands (and will expect unencrypted responses). They won't understand each other. Actually it will never even get to that, as after responding to AUTH, the server will initiate TLS handshake and that will fail straight away.
I am trying to develop a web application with php that will connect to an 11g oracle database.
Here is my code:
//database parameter
$db_name = "my_base";
$user = "username";
$password = "password";
$sid = "sid_number";
$port = "1521";
//function of connection
$conn = oci_connect ($user, $password, "//localhost/".$db_name);
Is the connection line correct? Also I'm not introducing the port number and sid. Can someone tell me if the port number and sid are required or not?
Your connection string is correct it's not required port number & service number but if aren't able to connect & you changed the default setting you can always add port number & service in your connection string like this [//]host_name[:port][/service_name][:server_type][/instance_name] read more from here http://php.net/manual/en/function.oci-connect.php#refsect1-function.oci-connect-parameters
I've set up Active Directory and ADLDAP on Windows server 2012. I'm trying a simple ldap_bind but continue to have a "invalid credentials" error spit back to me.
In my AD Users and Groups screen, I clearly see the domain I made along with the OU (organizational unit) and users inside of it. ASDI Edit clearly tells me the DN for that user:
CN=Bob Smith,OU=Accounting,DC=mydomain,DC=net
Further, the BaseDN is clearly told to me in ASDI Edit because it's above the OU group "accounting" -
DC=mydomain,DC=net
Now onto my script - which throws no LDAP connect errors, only on bind, with a constant invalid credentials:
$connectionLDAP = "LDAP://localhost:54126";
$basedn = 'DC=mydomain,DC=net';
$ldap = ldap_connect($connectionLDAP) or die("Could not connect to LDAP server.");
$username = $post['username'];
$password = $post['password'];
$usernameForBind = "CN=".$username.",OU=Accounting,".$basedn;
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
$bind = ldap_bind($ldap, $usernameForBind, $password);
This spits the following warning, and of course my script ends there since there is no positive match to username and password found:
Warning: ldap_bind(): Unable to bind to server: Invalid credentials in C:\....\login.php on line 41
And the below error echos produce this:
echo(ldap_error($ldap)."<br>");
echo(ldap_errno($ldap)."<br>");
Invalid credentials
49
I have tried every combination of DN, username, email address, mydomain\username without the rest of the DN info, everything I can think of....but for the life of me it won't take, and google + Stack searches unfortunately aren't helping me at the moment get past this.
Thanks for any assistance.
You are using Active directory on Windows, So please change your code to following It would work. Because AD need #domain_name as username suffix in bind function.
$connectionLDAP = "ldap://localhost";
$basedn = '#mydomain.net';
$ldap = #ldap_connect($connectionLDAP, 54126) or die("Could not connect to LDAP server.");
$username = $post['username'];
$password = $post['password'];
$usernameForBind = $username.$basedn;
#ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
#ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
$bind = #ldap_bind($ldap, $usernameForBind, $password);
I've tested such scenarios many times, It works for AD.
And also Please make sure that your AD server is running on the same port you're using in code ie. 54126.
I am trying to implement a PHP script that will ping an IP on a specific port and echo out whether the server is online / offline. This way, users will be able to see if non-access to the server is a server fault or a own network problem.
The site is currently on http://Dev.stevehamber.com. You can see the "Online" is wrapped in a class of 'PHP' and I need this to reflect if the server is online or offline. The application runs on port TCP=25565 so I need the output to show if this port is reachable or not.
Here is a snippet I found that is (I suppose) what I'm looking for:
<?php
$host = 'www.example.com';
$up = ping($host);
// if site is up, send them to the site.
if( $up ) {
header('Location: http://'.$host);
}
// otherwise, take them to another one of our sites and show them a descriptive message
else {
header('Location: http://www.anothersite.com/some_message');
}
?>
How can I replicate something like this on my page?
Based on the comments on the question, fsockopen() is the simplest and most widely available way to accomplish this task.
<?php
// Host name or IP to check
$host = 'www.example.com';
// Number of seconds to wait for a response from remote host
$timeout = 2;
// TCP port to connect to
$port = 25565;
// Try and connect
if ($sock = fsockopen($host, $port, $errNo, $errStr, $timeout)) {
// Connected successfully
$up = TRUE;
fclose($sock); // Drop connection immediately for tidiness
} else {
// Connection failed
$up = FALSE;
}
// Display something
if ($up) {
echo "The server at $host:$port is up and running :-D";
} else {
echo "I couldn't connect to the server at $host:$port within $timeout seconds :-(<br>\nThe error I got was $errNo: $errStr";
}
Note that all this does is test whether the server is accepting connections on TCP:25565. It does not do anything to verify that the application listening on this port is actually the application you are looking for, or that it is functioning correctly.
This has been bothering me for awhile, can some one show me how to ping a counter strike server.
I just want to ping the server and see if it is online, thats all.
I found many small snippets online that were using fsock and UDP to do this but none of them actually did the job i wanted it to do.
Most of the ones i found were showing offline servers as online.
I would really really appreciate if some one could provide me with this useful information (code).
Thank you in advance ^_^
you can't just ping the server since it uses UDP instead of normal TCP, so in order to check it's status you need to "query" the server, you can find information about what command you can send to CS servers here: http://developer.valvesoftware.com/wiki/Server_queries#A2A_PING
Anyway the following code (PHP) can be used to check CS server status.
`
`
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_connect($socket, "cs.somesv.com", 27015);
socket_write($socket, "\xFF\xFF\xFF\xFF\x69");
if (#socket_read($socket, 5) == "\xFF\xFF\xFF\xFF\x6A") {
echo '<FONT COLOR=lime>Online</FONT>';
} else {
echo '<FONT COLOR=red>Offline</FONT>';
}
socket_close($socket);
?>`
Bah! this code blocks don't really work fine! :(
Anyway, I use this code everyday for my server, hope it works fine for you.
Two choices off the top of my head:
fsockopen:
http://www.phptoys.com/e107_plugins/content/content.php?content.41
Net_Ping Pear package:
http://www.codediesel.com/php/ping-a-server-using-php/
Using IP of the CS server.
Get ClanManager and it has modules to check status of CS server.
This is the file with examples talking with CS servers,
http://clanmanager.cvs.sourceforge.net/viewvc/clanmanager/ocm/server/counterstrike.inc?revision=1.3&view=markup
You can also do what's known as a TCP ping. Basically, you just connect then disconnect without any communication. If the connection succeeds, you know the server is up, if it fails it's down. When I say server I mean the program you're interested in, not the physical server.
Here is PHP function to check if CS server is online:
function isCsServerOnline($server, $port = 27015)
{
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
// timeout 1.5 seconds
$timeout = array('sec' => 1, 'usec' => 500000);
socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, $timeout);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, $timeout);
#socket_connect($socket, $server, $port);
#socket_write($socket, "\xFF\xFF\xFF\xFF\x69");
$isOnline = #socket_read($socket, 5) == "\xFF\xFF\xFF\xFF\x6A";
#socket_close($socket);
return $isOnline;
}
You can use it like this:
$server = 'some.cs.server';
$port = 27015;
$isOnline = isCsServerOnline($server, $port);
echo $isOnline ? 'Online' : 'Offline';