您好,我想向您展示我在做什么,因为我的 PHP 或我的 iOS 没有将文件发送到 FTP 服务器:S
iOS端:
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
NSString *nombreArchivo = @"wtthdb.db";
NSData *archivo = [NSData dataWithContentsOfFile:[[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:nombreArchivo]]];
NSLog(@"Tamaño del archivo %i",[archivo length]);
NSMutableString *post = [[NSMutableString alloc] initWithFormat:@"file=%@&filename=%@",archivo,nombreArchivo];
[post appendFormat:@"%@",archivo];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSURL *url = [NSURL URLWithString:@"http://zsoft.es/subidaios.php"];
NSMutableURLRequest *peticion = [NSMutableURLRequest requestWithURL:url];
NSURLConnection *con;
@try
{
[peticion setHTTPMethod:@"POST"];
[peticion setValue:postLength forHTTPHeaderField:@"Content-Length"];
[peticion setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[peticion setHTTPBody:postData];
con = [NSURLConnection connectionWithRequest:peticion delegate:self];
[con start];
}
@catch (NSException *e)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error del servidor"
message:[NSString stringWithFormat:@"Error: %@",e]
delegate:self
cancelButtonTitle:@"Aceptar"
otherButtonTitles:nil];
[alert show];
}
NSLog(@"Empezado");
这是我的 PHP 方面:
<?php
if (isset($_POST['name']) && isset($_POST['filename']))
{
$name = $_POST['name'];
$filename = $_POST['filename'];
$ftp = ftp_connect("ftp.marinesignal.com");
ftp_login($ftp, "user", "pass");
ftp_pasv($ftp, true);
ftp_put($ftp,$filename,$name,FTP_BINARY);
ftp_close($ftp);
}
?>
而且我不知道如何通过 XCode 调试我的 PHP 代码......
谢谢!!