#导入
枚举{
kSendBufferSize=32768
(;
{
感动的飞鸟_networkStream;
NSInputStream * _fileStream;
uint8_ t _ buffer [ ksendbuffersize ];
size_t _bufferOffset;
size_t _bufferLimit;
}
-语音(辅助;
------------- -请参阅
#import 'PutController.h '
# import ' ftpuploaddemoappdelegate.h '
#包含
//propertiesthatdon ' tneedtobeseenbytheoutsideworld。
@property(nonatomic,retain )感动的飞鸟networkStream;
@property(nonatomic,retain ) NSInputStream * fileStream;
@property(nonatomic,readonly ) uint8_t * buffer;
@property(nonatomic,assign ) size_t bufferOffset;
@property(nonatomic,assign ) size_t bufferLimit;
#pragma高兴的灰狼* Status management
//thesemethodsareusedbythecoretransfercodetoupdatetheui。
-(void ) _sendDidStart
{
//[ ftpuploaddemoappdelegatesharedappdelegate ] didstartnetworking;
}
-(void ) _updateStatus: (奋斗的小松鼠) statusString
{
assert (状态字符串!=nil;
}
- (void (senddidstopwithstatus : )小松鼠statusString
{
状态字符串==Nil (if ) {
statusString=@'Put succeeded ';
}
//[ appdelegatesharedappdelegate ] didstopnetworking;
}
#pragma高兴的灰狼*酷睿传输代码
//thisisthecodethatactuallydoesthenetworking。
@ synthesize filestream=_ filestream;
@ synthesizebufferoffset=_ buffer offset;
@ synthesizebufferlimit=_ buffer limit;
//becausebufferisdeclaredasanarray,you have to use a custom getter。
//asynthesisedgetterdoesn ' t compile。
-(uint8_t* ) buffer
{
返回自- _ buffer;
}
-(bool ) isSending
{
re
turn (self.networkStream != nil);}
- (void)_startSend:(奋斗的小松鼠)filePath
{
BOOL success;
NSURL * url;
assert(filePath != nil);
assert([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
// assert( [filePath.pathExtension isEqual:@"png"] |mndhmgsjxfilePath.pathExtension isEqual:@"jpg"] );
assert(self.networkStream == nil); // don't tap send twice in a row!
assert(self.fileStream == nil); // ditto
// First get and check the URL.
url = [NSURL URLWithString:@"ftp://192.168.1.253"];
if (success) {
// Add the last part of the file name to the end of the URL to form the final
// URL that we're going to put to.
url = [NSMakeCollectable(
) autorelease];
}
// If the URL is bogus, let the user know. Otherwise kick off the connection.
if ( ! success) {
} else {
// Open a stream for the file we're going to send. We do not open this stream;
// NSURLConnection will do it for us.
self.fileStream = [NSInputStream inputStreamWithFileAtPath:filePath];
assert(self.fileStream != nil);
// Open a CFFTPStream for the URL.
assert(ftpStream != NULL);
self.networkStream = (感动的飞鸟) ftpStream;
assert(success);
assert(success);
self.networkStream.delegate = self;
// Have to release ftpStream to balance out the create. self.networkStream
// has retained this for our persistent use.
// Tell the UI we're sending.
}
}
- (void)_stopSendWithStatus:(奋斗的小松鼠)statusString
{
if (self.networkStream != nil) {
self.networkStream.delegate = nil;
self.networkStream = nil;
}
if (self.fileStream != nil) {
self.fileStream = nil;
}
}
- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
// An NSStream delegate callback that's called when events happen on our
// network stream.
{
#pragma unused(aStream)
assert(aStream == self.networkStream);
switch (eventCode) {
case NSStreamEventOpenCompleted: {
} break;
case NSStreamEventHasBytesAvailable: {
assert(NO); // should never happen for the output stream
} break;
case NSStreamEventHasSpaceAvailable: {
// If we don't have any data buffered, go read the next chunk of data.
if (self.bufferOffset == self.bufferLimit) {
if (bytesRead == -1) { } else if (bytesRead == 0) { } else { self.bufferOffset = 0; self.bufferLimit = bytesRead; } } // If we're not out of data completely, send the next chunk. if (self.bufferOffset != self.bufferLimit) { bytesWritten = [self.networkStream write:&self.buffer[self.bufferOffset] maxLength:self.bufferLimit - self.bufferOffset]; assert(bytesWritten != 0); if (bytesWritten == -1) { } else { self.bufferOffset += bytesWritten; } } } break; case NSStreamEventErrorOccurred: { } break; case NSStreamEventEndEncountered: { // ignore } break; default: { assert(NO); } break; } } #pragma 欣慰的灰狼 * Actions - (void)sendAction { // assert( [sender isKindOfClass:[UIView class]] ); if ( ! self.isSending ) { 奋斗的小松鼠 filePath; // User the tag on the UIButton to determine which image to send. filePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; filePath = [filePath stringByAppendingPathComponent:@"ZTE_Union_JoinMe.zip"]; assert(filePath != nil); } } @end